Movatterモバイル変換


[0]ホーム

URL:


Skip to content

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

Sign up
Appearance settings

Commit58364e2

Browse files
cacresportobar
andauthored
script to search for and complete probable 'index entries' (#2706)
Si trabajamos con el `.po` directo no es sencillo identificar aquellasentradas que están vinculadas con la contrucción del índice general (yno con la página específica que se está traduciendo) .[Acá](https://t.me/python_docs_es/21686) más contexto.Dado que mayormente son nombres de funciones, clases, etc. una de laspropuestas es mantener el índice sin traducir y asegurar consistencia enlos conceptos.Este script toma un `.po` específico (o varios) y recorre una a una lasentradas, **identifica posibles entradas de índice** -a partir del ordenen el file- y **ofrece completar la traducción** con el mismo contenidoque el original.---------Co-authored-by: rtobar <rtobarc@gmail.com>
1 parent453257b commit58364e2

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

‎scripts/complete_index.py

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp