8000 Update scripts/complete_index.py · python/python-docs-es@f3f4dc6 · GitHub
[go: up one dir, main page]

Skip to content
< 8000 header class="HeaderMktg header-logged-out js-details-container js-header Details f4 py-3" role="banner" data-is-top="true" data-color-mode=light data-light-theme=light data-dark-theme=dark>

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f3f4dc6

Browse files
committed
Update scripts/complete_index.py
Apply suggestions from @rtobar
1 parent a89bcfd commit f3f4dc6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

scripts/complete_index.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ def out_of_order_entries(po_file):
2222
Compare the order of source lines against the order in which they appear in
2323
the file, and return a generator with entries that are out of order.
2424
"""
25-
po_file = polib.pofile(po_file)
2625
po_entries = [entry for entry in po_file if not entry.obsolete]
2726
val_max = 0
2827

2928
for entry in po_entries:
3029
source_index = int(entry.occurrences[0][1])
3130

3231
if source_index <= val_max:
33-
yield(entry)
34-
po_file.save()
32+
yield entry
3533

3634
val_max = max(val_max, source_index)
3735

@@ -50,22 +48,26 @@ def complete_index(po_files=None):
5048
if not po_files:
5149
po_files = Path(".").glob("**/*.po")
5250

53-
for po_file in po_files:
51+
for po_file_path in po_files:
52+
5453
try:
54+
po_file = polib.pofile(po_file_path)
55+
5556
# Ask to complete entries out of order with original text
5657
for entry in out_of_order_entries(po_file):
5758
user_input = input(f"\n{entry}\nIs this a index entry? (y/N):")
5859
if user_input.lower() == "y":
5960
entry.msgstr = entry.msgid
61+
po_file.save() # Save if an entry has been modified
6062

6163
except KeyboardInterrupt:
6264
break
6365

6466
except Exception as e:
65-
print(f"Error! file {po_file}: {e}\n")
67+
print(f"Error! file {po_file_path}: {e}\n")
6668

6769
else:
68-
print(f"{po_file} processed!\n")
70+
print(f"\n---\n{po_file_path} processed!\n---")
6971

7072

7173
if __name__ == "__main__":

0 commit comments

Comments
 (0)
0