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

Commit526a3f2

Browse files
committed
Mejorar script para encontrar diferencias de formato
Este script puede ser utilizaro en archivos, directorios,o en todo el proyecto (sin argumentos)La idea es encontrar inconsistencias en los archivos traducidosrelacionados al formato de rst y sphinx.
1 parent83c5e7e commit526a3f2

File tree

1 file changed

+102
-47
lines changed

1 file changed

+102
-47
lines changed

‎scripts/format_differences.py

Lines changed: 102 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,111 @@
11
importcollections
2-
importos
3-
importglob
4-
2+
importre
3+
importsys
4+
frompathlibimportPath
55
frompprintimportpprint
6-
7-
importpolib# fades
8-
9-
PO_DIR=os.path.abspath(
10-
os.path.join(
11-
os.path.dirname(__file__),
12-
'..',
13-
))
14-
15-
16-
17-
DELIMITERS= ("``","*")
18-
19-
defhas_delimiters(x):
20-
fordinDELIMITERS:
21-
ifdinx:
22-
returnTrue
23-
returnFalse
24-
25-
defmain():
26-
files_with_differences=collections.defaultdict(list)
27-
28-
fori,pofilenameinenumerate(glob.glob(PO_DIR+'**/**/*.po')):
6+
fromtypingimportList
7+
8+
importpolib
9+
10+
_patterns= [
11+
":c:func:`[^`]+`",
12+
":c:type:`[^`]+`",
13+
":c:macro:`[^`]+`",
14+
":c:member:`[^`]+`",
15+
":c:data:`[^`]+`",
16+
":py:data:`[^`]+`",
17+
":py:mod:`[^`]+`",
18+
":func:`[^`]+`",
19+
":mod:`[^`]+`",
20+
":ref:`[^`]+`",
21+
":class:`[^`]+`",
22+
":pep:`[^`]+`",
23+
":data:`[^`]+`",
24+
":exc:`[^`]+`",
25+
":term:`[^`]+`",
26+
":meth:`[^`]+`",
27+
":envvar:`[^`]+`",
28+
":file:`[^`]+`",
29+
":attr:`[^`]+`",
30+
":const:`[^`]+`",
31+
":issue:`[^`]+`",
32+
":opcode:`[^`]+`",
33+
":option:`[^`]+`",
34+
":program:`[^`]+`",
35+
":keyword:`[^`]+`",
36+
":RFC:`[^`]+`",
37+
":rfc:`[^`]+`",
38+
":doc:`[^`]+`",
39+
"``[^`]+``",
40+
"`[^`]+`__",
41+
"`[^`]+`_",
42+
"\*\*[^\*]+\*\*",# bold text between **
43+
"\*[^\*]+\*",# italic text between *
44+
]
45+
46+
_exps= [re.compile(e)forein_patterns]
47+
48+
49+
defget_sphinx_directives(s:str)->List[str]:
50+
"""
51+
Parameters:
52+
string containing the text to translate
53+
54+
Returns:
55+
dictionary containing all the placeholder text as keys
56+
and the correct value.
57+
"""
58+
59+
output:List[str]= []
60+
forexpin_exps:
61+
matches=exp.findall(s)
62+
formatchinmatches:
63+
output.append(match)
64+
# remove the found pattern from the original string
65+
s=s.replace(match,"")
66+
returnoutput
67+
68+
defind(level=0):
69+
returnf"{' '*4*level}"
70+
71+
if__name__=="__main__":
72+
PO_DIR=Path(__file__).resolve().parent.parent
73+
VENV_DIR=PO_DIR/"venv"
74+
75+
iflen(sys.argv)>1:
76+
filename=sys.argv[1]
77+
files= []
78+
iffilename:
79+
ifPath(filename).is_dir():
80+
files= [iforiinPO_DIR.glob(f"{filename}/*.po")ifnoti.is_relative_to(VENV_DIR)]
81+
elifnotPath(filename).is_file():
82+
print(f"File not found: '{filename}'")
83+
sys.exit(-1)
84+
else:
85+
files= [filename]
86+
else:
87+
files= [iforiinPO_DIR.glob("**/**/*.po")ifnoti.is_relative_to(VENV_DIR)]
88+
89+
fori,pofilenameinenumerate(files):
90+
print(f"\n> Processing{pofilename}")
2991
po=polib.pofile(pofilename)
30-
ifpo.percent_translated()<85:
31-
continue
3292

3393
forentryinpo:
34-
words= []
35-
wordsid=wordsstr=list()
36-
37-
ifhas_delimiters(entry.msgid):
38-
wordsid= [wordforwordinentry.msgid.split()ifhas_delimiters(word)]
39-
40-
ifhas_delimiters(entry.msgstr):
41-
wordsstr= [wordforwordinentry.msgstr.split()ifhas_delimiters(word)]
4294

43-
iflen(wordsid)!=len(wordsstr):
44-
key=pofilename.replace(PO_DIR,'')
45-
files_with_differences[key].append({
46-
'occurrences':entry.occurrences,
47-
'words': {
48-
'original':wordsid,
49-
'translated':wordsstr,
50-
},
51-
})
95+
directives_id=get_sphinx_directives(entry.msgid)
96+
directives_str=get_sphinx_directives(entry.msgstr)
5297

53-
returnfiles_with_differences
98+
# Check if any of them is not empty
99+
ifdirectives_idordirectives_str:
54100

101+
# Check if the directives are the same
102+
forori,dstinzip(directives_id,directives_str):
103+
ifori==dst:
104+
continue
55105

56-
pprint(main())
106+
ifori!=dst:
107+
occs= [f"{ind(2)}{t[0]}:{t[1]}"fortinentry.occurrences]
108+
print(f"\n{ind(1)}{pofilename}:{entry.linenum}")
109+
print(f"\n".join(occs))
110+
print(f"{ind(3)}{ori}")
111+
print(f"{ind(3)}{dst}")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp