File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 77from pathlib import Path
88
99def 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
1720def 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
3238def main ():
3339 po_dir = Path ('po' )
You can’t perform that action at this time.
0 commit comments