author | Anton Shestakov <av6@dwimlabs.net> |
Thu, 08 Aug 2024 17:28:38 +0400 | |
branch | stable |
changeset 51795 | 73476a9e5ced |
parent 48875 | 6000f5b25c9b |
child 51863 | f4733654f144 |
permissions | -rwxr-xr-x |
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
1 |
#!/usr/bin/env python3 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
2 |
# |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
3 |
# check-translation.py - check Mercurial specific translation problems |
33899
078099304772
i18n: update check-translation script to pass import checker
Augie Fackler <raf@durin42.com>
parents:
33715
diff
changeset
|
4 |
|
078099304772
i18n: update check-translation script to pass import checker
Augie Fackler <raf@durin42.com>
parents:
33715
diff
changeset
|
5 |
import re |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
6 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
7 |
import polib |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 |
|
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
9 |
scanners = [] |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
10 |
checkers = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
11 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
12 |
|
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
13 |
def scanner(): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
14 |
def decorator(func): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
15 |
scanners.append(func) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
16 |
return func |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
17 |
|
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
18 |
return decorator |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
19 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
20 |
|
22203
35c2ea4ca26f
cleanup: rename check-translation.py checker function - don't hide global var
Mads Kiilerich <madski@unity3d.com>
parents:
20515
diff
changeset
|
21 |
def levelchecker(level, msgidpat): |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
22 |
def decorator(func): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
23 |
if msgidpat: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
24 |
match = re.compile(msgidpat).search |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
25 |
else: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
26 |
match = lambda msgid: True |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
27 |
checkers.append((func, level)) |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
28 |
func.match = match |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
29 |
return func |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
30 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
31 |
return decorator |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
32 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
33 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
34 |
def match(checker, pe): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
35 |
"""Examine whether POEntry "pe" is target of specified checker or not""" |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 |
if not checker.match(pe.msgid): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
37 |
return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 |
# examine suppression by translator comment |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 |
nochecker = 'no-%s-check' % checker.__name__ |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 |
for tc in pe.tcomment.split(): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
41 |
if nochecker == tc: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
42 |
return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
43 |
return True |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
44 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
45 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
46 |
#################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
47 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
48 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
49 |
def fatalchecker(msgidpat=None): |
22203
35c2ea4ca26f
cleanup: rename check-translation.py checker function - don't hide global var
Mads Kiilerich <madski@unity3d.com>
parents:
20515
diff
changeset
|
50 |
return levelchecker('fatal', msgidpat) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
51 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
52 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
53 |
@fatalchecker(r'\$\$') |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
54 |
def promptchoice(pe): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
55 |
"""Check translation of the string given to "ui.promptchoice()" |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
56 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
57 |
>>> pe = polib.POEntry( |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
58 |
... msgid ='prompt$$missing &sep$$missing &$$followed by &none', |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
59 |
... msgstr='prompt missing &sep$$missing amp$$followed by none&') |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
60 |
>>> match(promptchoice, pe) |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
61 |
True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
62 |
>>> for e in promptchoice(pe): print(e) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
63 |
number of choices differs between msgid and msgstr |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
64 |
msgstr has invalid choice missing '&' |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
65 |
msgstr has invalid '&' followed by none |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
66 |
""" |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
67 |
idchoices = [c.rstrip(' ') for c in pe.msgid.split('$$')[1:]] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
68 |
strchoices = [c.rstrip(' ') for c in pe.msgstr.split('$$')[1:]] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
70 |
if len(idchoices) != len(strchoices): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 |
yield "number of choices differs between msgid and msgstr" |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
72 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
73 |
indices = [(c, c.find('&')) for c in strchoices] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
74 |
if [c for c, i in indices if i == -1]: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
75 |
yield "msgstr has invalid choice missing '&'" |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
76 |
if [c for c, i in indices if len(c) == i + 1]: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
77 |
yield "msgstr has invalid '&' followed by none" |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
78 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
79 |
|
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
80 |
deprecatedpe = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
81 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
82 |
|
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
83 |
@scanner() |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
84 |
def deprecatedsetup(pofile): |
26852
3fb36dec1727
i18n: do not abuse msgstr of "DEPRECATED" to check for bad translation
Yuya Nishihara <yuya@tcha.org>
parents:
26838
diff
changeset
|
85 |
pes = [p for p in pofile if p.msgid == '(DEPRECATED)' and p.msgstr] |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
86 |
if len(pes): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
87 |
global deprecatedpe |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
88 |
deprecatedpe = pes[0] |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
89 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
90 |
|
26837
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
91 |
@fatalchecker(r'\(DEPRECATED\)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
92 |
def deprecated(pe): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
93 |
"""Check for DEPRECATED |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
94 |
>>> ped = polib.POEntry( |
26852
3fb36dec1727
i18n: do not abuse msgstr of "DEPRECATED" to check for bad translation
Yuya Nishihara <yuya@tcha.org>
parents:
26838
diff
changeset
|
95 |
... msgid = '(DEPRECATED)', |
3fb36dec1727
i18n: do not abuse msgstr of "DEPRECATED" to check for bad translation
Yuya Nishihara <yuya@tcha.org>
parents:
26838
diff
changeset
|
96 |
... msgstr= '(DETACERPED)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
97 |
>>> deprecatedsetup([ped]) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
98 |
>>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
99 |
... msgid = 'Something (DEPRECATED)', |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
100 |
... msgstr= 'something (DEPRECATED)') |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
101 |
>>> match(deprecated, pe) |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
102 |
True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
103 |
>>> for e in deprecated(pe): print(e) |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
104 |
>>> pe = polib.POEntry( |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
105 |
... msgid = 'Something (DEPRECATED)', |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
106 |
... msgstr= 'something (DETACERPED)') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
107 |
>>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
108 |
True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
109 |
>>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
110 |
>>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
111 |
... msgid = 'Something (DEPRECATED)', |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
112 |
... msgstr= 'something') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
113 |
>>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
114 |
True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
115 |
>>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
116 |
msgstr inconsistently translated (DEPRECATED) |
26837
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
117 |
>>> pe = polib.POEntry( |
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
118 |
... msgid = 'Something (DEPRECATED, foo bar)', |
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
119 |
... msgstr= 'something (DETACERPED, foo bar)') |
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
120 |
>>> match(deprecated, pe) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
121 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
122 |
if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
123 |
'(DEPRECATED)' in pe.msgstr |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
124 |
or (deprecatedpe and deprecatedpe.msgstr in pe.msgstr) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
125 |
): |
26276
93395bee98ba
tests: cleanup check-translation deprecated
timeless@mozdev.org
parents:
26261
diff
changeset
|
126 |
yield "msgstr inconsistently translated (DEPRECATED)" |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
127 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
128 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
129 |
#################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
130 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
131 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
132 |
def warningchecker(msgidpat=None): |
22203
35c2ea4ca26f
cleanup: rename check-translation.py checker function - don't hide global var
Mads Kiilerich <madski@unity3d.com>
parents:
20515
diff
changeset
|
133 |
return levelchecker('warning', msgidpat) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
134 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
135 |
|
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
136 |
@warningchecker() |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
137 |
def taildoublecolons(pe): |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
138 |
"""Check equality of tail '::'-ness between msgid and msgstr |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
139 |
|
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
140 |
>>> pe = polib.POEntry( |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
141 |
... msgid ='ends with ::', |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
142 |
... msgstr='ends with ::') |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
143 |
>>> for e in taildoublecolons(pe): print(e) |
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
144 |
>>> pe = polib.POEntry( |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
145 |
... msgid ='ends with ::', |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
146 |
... msgstr='ends without double-colons') |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
147 |
>>> for e in taildoublecolons(pe): print(e) |
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
148 |
tail '::'-ness differs between msgid and msgstr |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
149 |
>>> pe = polib.POEntry( |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
150 |
... msgid ='ends without double-colons', |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
151 |
... msgstr='ends with ::') |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
152 |
>>> for e in taildoublecolons(pe): print(e) |
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
153 |
tail '::'-ness differs between msgid and msgstr |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
154 |
""" |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
155 |
if pe.msgid.endswith('::') != pe.msgstr.endswith('::'): |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
156 |
yield "tail '::'-ness differs between msgid and msgstr" |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
157 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
158 |
|
20515
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
159 |
@warningchecker() |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
160 |
def indentation(pe): |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
161 |
"""Check equality of initial indentation between msgid and msgstr |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
162 |
|
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
163 |
This may report unexpected warning, because this doesn't aware |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
164 |
the syntax of rst document and the context of msgstr. |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
165 |
|
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
166 |
>>> pe = polib.POEntry( |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
167 |
... msgid =' indented text', |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
168 |
... msgstr=' narrowed indentation') |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
169 |
>>> for e in indentation(pe): print(e) |
20515
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
170 |
initial indentation width differs betweeen msgid and msgstr |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
171 |
""" |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
172 |
idindent = len(pe.msgid) - len(pe.msgid.lstrip()) |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
173 |
strindent = len(pe.msgstr) - len(pe.msgstr.lstrip()) |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
174 |
if idindent != strindent: |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
175 |
yield "initial indentation width differs betweeen msgid and msgstr" |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
176 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
177 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
178 |
#################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
179 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
180 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
181 |
def check(pofile, fatal=True, warning=False): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
182 |
targetlevel = {'fatal': fatal, 'warning': warning} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
183 |
targetcheckers = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
184 |
(checker, level) for checker, level in checkers if targetlevel[level] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
185 |
] |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
186 |
if not targetcheckers: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
187 |
return [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
188 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
189 |
detected = [] |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
190 |
for checker in scanners: |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
191 |
checker(pofile) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
192 |
for pe in pofile.translated_entries(): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
193 |
errors = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
194 |
for checker, level in targetcheckers: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
195 |
if match(checker, pe): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
196 |
errors.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
197 |
(level, checker.__name__, error) for error in checker(pe) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
198 |
) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
199 |
if errors: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
200 |
detected.append((pe, errors)) |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
201 |
return detected |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
202 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
203 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
204 |
######################################## |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
205 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
206 |
if __name__ == "__main__": |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
207 |
import sys |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
208 |
import optparse |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
209 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
210 |
optparser = optparse.OptionParser( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
211 |
"""%prog [options] pofile ... |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
212 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
213 |
This checks Mercurial specific translation problems in specified |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
214 |
'*.po' files. |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
215 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
216 |
Each detected problems are shown in the format below:: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
217 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
218 |
filename:linenum:type(checker): problem detail ..... |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
219 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
220 |
"type" is "fatal" or "warning". "checker" is the name of the function |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
221 |
detecting corresponded error. |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
222 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
223 |
Checking by checker "foo" on the specific msgstr can be suppressed by |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
224 |
the "translator comment" like below. Multiple "no-xxxx-check" should |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
225 |
be separated by whitespaces:: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
226 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
227 |
# no-foo-check |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
228 |
msgid = "....." |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
229 |
msgstr = "....." |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
230 |
""" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
231 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
232 |
optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
233 |
"", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
234 |
"--warning", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
235 |
help="show also warning level problems", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
236 |
action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
237 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
238 |
optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
239 |
"", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
240 |
"--doctest", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
241 |
help="run doctest of this tool, instead of check", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
242 |
action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
243 |
) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
244 |
(options, args) = optparser.parse_args() |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
245 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
246 |
if options.doctest: |
20164
1ddf4409229f
tests: fix missing import in check-translations
Matt Mackall <mpm@selenic.com>
parents:
20158
diff
changeset
|
247 |
import os |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
248 |
|
20158
209e04a06467
tests: fix Mac doctest escape code garbage for check-translations
Matt Mackall <mpm@selenic.com>
parents:
20152
diff
changeset
|
249 |
if 'TERM' in os.environ: |
209e04a06467
tests: fix Mac doctest escape code garbage for check-translations
Matt Mackall <mpm@selenic.com>
parents:
20152
diff
changeset
|
250 |
del os.environ['TERM'] |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
251 |
import doctest |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
252 |
|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
253 |
failures, tests = doctest.testmod() |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
254 |
sys.exit(failures and 1 or 0) |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
255 |
|
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
256 |
detected = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
257 |
warning = options.warning |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
258 |
for f in args: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
259 |
detected.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
260 |
(f, pe, errors) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
261 |
for pe, errors in check(polib.pofile(f), warning=warning) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
262 |
) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
263 |
if detected: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
264 |
for f, pe, errors in detected: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
265 |
for level, checker, error in errors: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
266 |
sys.stderr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
267 |
'%s:%d:%s(%s): %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
268 |
% (f, pe.linenum, level, checker, error) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
269 |
) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
270 |
sys.exit(1) |