Mercurial > hg
annotate i18n/check-translation.py @ 45095:8e04607023e5
procutil: ensure that procutil.std{out,err}.write() writes all bytes
Python 3 offers different kind of streams and it’s not guaranteed for all of
them that calling write() writes all bytes.
When Python is started in unbuffered mode, sys.std{out,err}.buffer are
instances of io.FileIO, whose write() can write less bytes for
platform-specific reasons (e.g. Linux has a 0x7ffff000 bytes maximum and could
write less if interrupted by a signal; when writing to Windows consoles, it’s
limited to 32767 bytes to avoid the "not enough space" error). This can lead to
silent loss of data, both when using sys.std{out,err}.buffer (which may in fact
not be a buffered stream) and when using the text streams sys.std{out,err}
(I’ve created a CPython bug report for that:
https://bugs.python.org/issue41221).
Python may fix the problem at some point. For now, we implement our own wrapper
for procutil.std{out,err} that calls the raw stream’s write() method until all
bytes have been written. We don’t use sys.std{out,err} for larger writes, so I
think it’s not worth the effort to patch them.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 10 Jul 2020 12:27:58 +0200 |
parents | 2372284d9457 |
children | c102b704edb5 |
rev | line source |
---|---|
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
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): |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
36 """Examine whether POEntry "pe" is target of specified checker or not |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
37 """ |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
38 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
|
39 return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
40 # 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
|
41 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
|
42 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
|
43 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
|
44 return |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
45 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
|
46 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
47 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
48 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
49 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
50 |
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 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
|
52 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
|
53 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
54 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
55 @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
|
56 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
|
57 """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
|
58 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
59 >>> 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
|
60 ... 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
|
61 ... 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
|
62 >>> 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
|
63 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
64 >>> 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
|
65 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
|
66 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
|
67 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
|
68 """ |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
69 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
|
70 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
|
71 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
72 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
|
73 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
|
74 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
81 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
82 deprecatedpe = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
83 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
84 |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
85 @scanner() |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
86 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
|
87 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
|
88 if len(pes): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
89 global deprecatedpe |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
90 deprecatedpe = pes[0] |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
91 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
92 |
26837
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
93 @fatalchecker(r'\(DEPRECATED\)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
94 def deprecated(pe): |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
95 """Check for DEPRECATED |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
96 >>> 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
|
97 ... msgid = '(DEPRECATED)', |
3fb36dec1727
i18n: do not abuse msgstr of "DEPRECATED" to check for bad translation
Yuya Nishihara <yuya@tcha.org>
parents:
26838
diff
changeset
|
98 ... msgstr= '(DETACERPED)') |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
99 >>> deprecatedsetup([ped]) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
100 >>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
101 ... msgid = 'Something (DEPRECATED)', |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
102 ... msgstr= 'something (DEPRECATED)') |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
103 >>> match(deprecated, pe) |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
104 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
105 >>> for e in deprecated(pe): print(e) |
26277
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
106 >>> pe = polib.POEntry( |
ad4d6c7aea6a
tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents:
26276
diff
changeset
|
107 ... msgid = 'Something (DEPRECATED)', |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
108 ... msgstr= 'something (DETACERPED)') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
109 >>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
110 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
111 >>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
112 >>> pe = polib.POEntry( |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
113 ... msgid = 'Something (DEPRECATED)', |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
114 ... msgstr= 'something') |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
115 >>> match(deprecated, pe) |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
116 True |
33715
29238dbf718e
i18n: fix check-translation.py to be less broken on Python 3
Augie Fackler <augie@google.com>
parents:
26852
diff
changeset
|
117 >>> for e in deprecated(pe): print(e) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
118 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
|
119 >>> pe = polib.POEntry( |
33894facc180
i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26277
diff
changeset
|
120 ... 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
|
121 ... 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
|
122 >>> match(deprecated, pe) |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
123 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
124 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
125 '(DEPRECATED)' in pe.msgstr |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
126 or (deprecatedpe and deprecatedpe.msgstr in pe.msgstr) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
127 ): |
26276
93395bee98ba
tests: cleanup check-translation deprecated
timeless@mozdev.org
parents:
26261
diff
changeset
|
128 yield "msgstr inconsistently translated (DEPRECATED)" |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
129 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
130 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
131 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
132 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
133 |
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 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
|
135 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
|
136 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
137 |
20514
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
138 @warningchecker() |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
139 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
|
140 """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
|
141 |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
142 >>> 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
|
143 ... 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
|
144 ... 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
|
145 >>> 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
|
146 >>> 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
|
147 ... 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
|
148 ... 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
|
149 >>> 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
|
150 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
|
151 >>> 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
|
152 ... 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
|
153 ... 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
|
154 >>> 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
|
155 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
|
156 """ |
410c80539c5c
i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20164
diff
changeset
|
157 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
|
158 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
|
159 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
160 |
20515
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
161 @warningchecker() |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
162 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
|
163 """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
|
164 |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
165 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
|
166 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
|
167 |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
168 >>> 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
|
169 ... 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
|
170 ... 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
|
171 >>> 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
|
172 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
|
173 """ |
6afbfb9b1af1
i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20514
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
179 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
180 #################### |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
181 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
182 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
183 def check(pofile, fatal=True, warning=False): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
184 targetlevel = {'fatal': fatal, 'warning': warning} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
185 targetcheckers = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
186 (checker, level) for checker, level in checkers if targetlevel[level] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
187 ] |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
188 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
|
189 return [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
190 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
191 detected = [] |
26261
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
192 for checker in scanners: |
8fb92ff63ccf
tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents:
22203
diff
changeset
|
193 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
|
194 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
|
195 errors = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
196 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
|
197 if match(checker, pe): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
198 errors.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
199 (level, checker.__name__, error) for error in checker(pe) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
200 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
205 |
20152
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 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
208 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
|
209 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
|
210 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
|
211 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
212 optparser = optparse.OptionParser( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
213 """%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
|
214 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
215 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
|
216 '*.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
|
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 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
|
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 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
|
221 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
222 "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
|
223 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
|
224 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
229 # 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
|
230 msgid = "....." |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
231 msgstr = "....." |
43076
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 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
234 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
235 "", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
236 "--warning", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
237 help="show also warning level problems", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
238 action="store_true", |
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 optparser.add_option( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
241 "", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
242 "--doctest", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
243 help="run doctest of this tool, instead of check", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
244 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
245 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
246 (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
|
247 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
248 if options.doctest: |
20164
1ddf4409229f
tests: fix missing import in check-translations
Matt Mackall <mpm@selenic.com>
parents:
20158
diff
changeset
|
249 import os |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
250 |
20158
209e04a06467
tests: fix Mac doctest escape code garbage for check-translations
Matt Mackall <mpm@selenic.com>
parents:
20152
diff
changeset
|
251 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
|
252 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
|
253 import doctest |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
254 |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
255 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
|
256 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
|
257 |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
258 detected = [] |
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
259 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
|
260 for f in args: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
261 detected.extend( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
262 (f, pe, errors) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
263 for pe, errors in check(polib.pofile(f), warning=warning) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
264 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
265 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
|
266 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
|
267 for level, checker, error in errors: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
268 sys.stderr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
269 '%s:%d:%s(%s): %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
270 % (f, pe.linenum, level, checker, error) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40185
diff
changeset
|
271 ) |
20152
84939b728749
i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff
changeset
|
272 sys.exit(1) |