Skip to content

Commit cc970fe

Browse files
committed
update action
1 parent c9c860d commit cc970fe

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/update_translations.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,33 @@
77
from pathlib import Path
88

99
def get_pot_date(po_file):
10-
"""Extract POT-Creation-Date line from PO file."""
10+
"""Extract POT-Creation-Date value from PO file."""
1111
with open(po_file, 'r', encoding='utf-8') as f:
1212
for line in f:
1313
if 'POT-Creation-Date:' in line:
14-
return line.rstrip('\n')
14+
# Extract just the date value
15+
match = re.search(r'POT-Creation-Date: ([^\\]+)', line)
16+
if match:
17+
return match.group(1)
1518
return None
1619

1720
def restore_pot_date(po_file, old_date):
18-
"""Restore POT-Creation-Date in PO file."""
21+
"""Restore POT-Creation-Date value in PO file."""
1922
if not old_date:
2023
return
2124

2225
with open(po_file, 'r', encoding='utf-8') as f:
23-
lines = f.readlines()
26+
content = f.read()
27+
28+
# Replace only the date value, keeping the line format
29+
content = re.sub(
30+
r'("POT-Creation-Date: )[^\\]+(\\n")',
31+
r'\g<1>' + old_date + r'\g<2>',
32+
content
33+
)
2434

2535
with open(po_file, 'w', encoding='utf-8') as f:
26-
for line in lines:
27-
if 'POT-Creation-Date:' in line:
28-
f.write(old_date + '\n')
29-
else:
30-
f.write(line)
36+
f.write(content)
3137

3238
def main():
3339
po_dir = Path('po')

0 commit comments

Comments
 (0)