@@ -22,16 +22,14 @@ def out_of_order_entries(po_file):
22
22
Compare the order of source lines against the order in which they appear in
23
23
the file, and return a generator with entries that are out of order.
24
24
"""
25
- po_file = polib .pofile (po_file )
26
25
po_entries = [entry for entry in po_file if not entry .obsolete ]
27
26
val_max = 0
28
27
29
28
for entry in po_entries :
30
29
source_index = int (entry .occurrences [0 ][1 ])
31
30
32
31
if source_index <= val_max :
33
- yield (entry )
34
- po_file .save ()
32
+ yield entry
35
33
36
34
val_max = max (val_max , source_index )
37
35
@@ -50,22 +48,26 @@ def complete_index(po_files=None):
50
48
if not po_files :
51
49
po_files = Path ("." ).glob ("**/*.po" )
52
50
53
- for po_file in po_files :
51
+ for po_file_path in po_files :
52
+
54
53
try :
54
+ po_file = polib .pofile (po_file_path )
55
+
55
56
# Ask to complete entries out of order with original text
56
57
for entry in out_of_order_entries (po_file ):
57
58
user_input = input (f"\n { entry } \n Is this a index entry? (y/N):" )
58
59
if user_input .lower () == "y" :
59
60
entry .msgstr = entry .msgid
61
+ po_file .save () # Save if an entry has been modified
60
62
61
63
except KeyboardInterrupt :
62
64
break
63
65
64
66
except Exception as e :
65
- print (f"Error! file { po_file } : { e } \n " )
67
+ print (f"Error! file { po_file_path } : { e } \n " )
66
68
67
69
else :
68
- print (f"{ po_file } processed!\n " )
70
+ print (f"\n --- \n { po_file_path } processed!\n --- " )
69
71
70
72
71
73
if __name__ == "__main__" :
0 commit comments