Skip to content

Commit e7400bf

Browse files
committed
Traducido archivo library/cgi.po
1 parent 2366ec8 commit e7400bf

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

scripts/completed_index.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/python
2+
"""
3+
Script to identify and complete general index entries with original content.
4+
5+
This script processes .po files, identifies out-of-order entries based on the
6+
source order, and completes them with original content.
7+
8+
Usage:
9+
python script_name.py [list of .po files]
10+
11+
If no list of .po files is provided, the script processes all .po files in the
12+
current directory and its immediate subdirectories.
13+
"""
14+
15+
from pathlib import Path
16+
import sys
17+
18+
import polib
19+
20+
21+
def out_of_order_entries(po_file):
22+
"""
23+
Compare the order of source lines against the order in which they appear in
24+
the file, and return a generator with entries that are out of order.
25+
"""
26+
po_entries = [entry for entry in po_file if not entry.obsolete]
27+
val_max = 0
28+
29+
for entry in po_entries:
30+
source_index = int(entry.occurrences[0][1])
31+
32+
if source_index <= val_max:
33+
yield entry
34+
35+
val_max = max(val_max, source_index)
36+
37+
38+
def complete_index(po_files=None):
39+
"""
40+
Identifies general index entries based on source order and completes them
41+
with original content.
42+
43+
args:
44+
po_files: List of .po files to process. If not provided, it processes
45+
all .po files in the current directory and immediate subdirectories.
46+
"""
47+
48+
# Read .po files
49+
if not po_files:
50+
po_files = Path(".").glob("**/*.po")
51+
52+
for po_file_path in po_files:
53+
54+
try:
55+
po_file = polib.pofile(po_file_path)
56+
57+
# Ask to complete entries out of order with original text
58+
for entry in out_of_order_entries(po_file):
59+
user_input = input(f"\n{entry}\nIs this a index entry? (y/N):")
60+
if user_input.lower() == "y":
61+
entry.msgstr = entry.msgid
62+
po_file.save() # Save if an entry has been modified
63+
64+
except KeyboardInterrupt:
65+
break
66+
67+
except Exception as e:
68+
print(f"Error! file {po_file_path}: {e}\n")
69+
70+
else:
71+
print(f"\n---\n{po_file_path} processed!\n---")
72+
73+
74+
if __name__ == "__main__":
75+
po_files = sys.argv[1:]
76+
complete_index(po_files)
77+

0 commit comments

Comments
 (0)