Mercurial > hg
annotate i18n/check-translation.py @ 48410:0b2469bf1227
python2-compat: fix extensions' tests on python2
They are minor output different to be taken in account.
Differential Revision: https://phab.mercurial-scm.org/D11861
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Sat, 04 Dec 2021 03:51:33 +0100 |
parents | 89a2afe31e82 |
children | 6000f5b25c9b |
rev | line source |
---|---|
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 from __future__ import absolute_import |
078099304772
i18n: update check-translation script to pass import checker
Augie Fackler <raf@durin42.com>
parents:
33715
diff
changeset
|
5 |
078099304772
i18n: update check-translation script to pass import checker
Augie Fackler <raf@durin42.com>
parents:
33715
diff
changeset
|
6 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
|
7 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
8 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
|
9 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
10 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
|
11 checkers = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
12 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
13 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
14 def scanner(): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
15 def decorator(func): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
16 scanners.append(func) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
17 return func |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
18 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
19 return decorator |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
20 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
21 |
22203
35c2ea4ca26f
cleanup: rename check-translation.py checker function - don't hide global var
Mads Kiilerich <madski@unity3d.com>
parents:
20515
diff
changeset
|
22 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
|
23 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
|
24 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
|
25 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
|
26 else: |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
27 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
|
28 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
|
29 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
|
30 return func |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
31 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
32 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
|
33 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
34 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
35 def match(checker, pe): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
36 """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
|
37 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
|
38 return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
39 # 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
|
40 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
|
41 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
|
42 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
|
43 return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
44 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
|
45 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
46 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
47 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
48 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
49 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
50 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
|
51 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
|
52 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
53 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
54 @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
|
55 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
|
56 """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
|
57 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
58 >>> 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
|
59 ... 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
|
60 ... 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
|
61 >>> 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
|
62 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
63 >>> 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
|
64 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
|
65 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
|
66 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
|
67 """ |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
68 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
|
69 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
|
70 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
71 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
|
72 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
|
73 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 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
|
79 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
80 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
81 deprecatedpe = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
82 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
83 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
84 @scanner() |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
85 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
|
86 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
|
87 if len(pes): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
88 global deprecatedpe |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
89 deprecatedpe = pes[0] |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
90 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
91 |
26837
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
92 @fatalchecker(r'\(DEPRECATED\)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
93 def deprecated(pe): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
94 """Check for DEPRECATED |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
95 >>> 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
|
96 ... msgid = '(DEPRECATED)', |
3fb36dec1727
i18n: do not abuse msgstr of "DEPRECATED" to check for bad translation
Yuya Nishihara <yuya@tcha.org>
parents:
26838
diff
changeset
|
97 ... msgstr= '(DETACERPED)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
98 >>> deprecatedsetup([ped]) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
99 >>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
100 ... msgid = 'Something (DEPRECATED)', |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
101 ... msgstr= 'something (DEPRECATED)') |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
102 >>> match(deprecated, pe) |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
103 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
104 >>> for e in deprecated(pe): print(e) |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
105 >>> pe = polib.POEntry( |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
106 ... msgid = 'Something (DEPRECATED)', |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
107 ... msgstr= 'something (DETACERPED)') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
108 >>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
109 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
110 >>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
111 >>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
112 ... msgid = 'Something (DEPRECATED)', |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
113 ... msgstr= 'something') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
114 >>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
115 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
116 >>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
117 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
|
118 >>> pe = polib.POEntry( |
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
119 ... 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
|
120 ... 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
|
121 >>> match(deprecated, pe) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
122 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
123 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
124 '(DEPRECATED)' in pe.msgstr |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
125 or (deprecatedpe and deprecatedpe.msgstr in pe.msgstr) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
126 ): |
26276
93395bee98ba
tests: cleanup check-translation deprecated
timeless@mozdev.org
parents:
26261
diff
changeset
|
127 yield "msgstr inconsistently translated (DEPRECATED)" |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
128 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
129 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
130 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
131 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
132 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
133 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
|
134 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
|
135 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
136 |
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
137 @warningchecker() |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
138 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
|
139 """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
|
140 |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
141 >>> 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
|
142 ... 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
|
143 ... 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
|
144 >>> 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
|
145 >>> 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
|
146 ... 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
|
147 ... 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
|
148 >>> 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
|
149 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
|
150 >>> 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
|
151 ... 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
|
152 ... 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
|
153 >>> 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
|
154 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
|
155 """ |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
156 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
|
157 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
|
158 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
159 |
20515
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
160 @warningchecker() |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
161 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
|
162 """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
|
163 |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
164 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
|
165 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
|
166 |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
167 >>> 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
|
168 ... 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
|
169 ... 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
|
170 >>> 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
|
171 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
|
172 """ |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 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
|
177 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
178 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
179 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
180 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
181 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
182 def check(pofile, fatal=True, warning=False): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
183 targetlevel = {'fatal': fatal, 'warning': warning} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
184 targetcheckers = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
185 (checker, level) for checker, level in checkers if targetlevel[level] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
186 ] |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
187 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
|
188 return [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
189 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
190 detected = [] |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
191 for checker in scanners: |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
192 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
|
193 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
|
194 errors = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
195 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
|
196 if match(checker, pe): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
197 errors.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
198 (level, checker.__name__, error) for error in checker(pe) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
199 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
204 |
20152
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 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
211 optparser = optparse.OptionParser( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
212 """%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
|
213 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
214 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
|
215 '*.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
|
216 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
217 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
|
218 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
219 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
|
220 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
221 "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
|
222 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
|
223 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
224 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
|
225 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
|
226 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
|
227 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
228 # 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
|
229 msgid = "....." |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
230 msgstr = "....." |
43076
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 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
233 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
234 "", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
235 "--warning", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
236 help="show also warning level problems", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
237 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
238 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
239 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
240 "", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
241 "--doctest", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
242 help="run doctest of this tool, instead of check", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
243 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
244 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
245 (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
|
246 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
247 if options.doctest: |
20164
1ddf4409229f
tests: fix missing import in check-translations
Matt Mackall <mpm@selenic.com>
parents:
20158
diff
changeset
|
248 import os |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
249 |
20158
209e04a06467
tests: fix Mac doctest escape code garbage for check-translations
Matt Mackall <mpm@selenic.com>
parents:
20152
diff
changeset
|
250 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
|
251 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
|
252 import doctest |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
253 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
254 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
|
255 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
|
256 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
257 detected = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
258 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
|
259 for f in args: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
260 detected.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
261 (f, pe, errors) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
262 for pe, errors in check(polib.pofile(f), warning=warning) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
263 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
264 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
|
265 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
|
266 for level, checker, error in errors: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
267 sys.stderr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
268 '%s:%d:%s(%s): %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
269 % (f, pe.linenum, level, checker, error) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
270 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
271 sys.exit(1) |