i18n/check-translation.py
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Sun, 01 Nov 2015 08:38:56 +0900
branchstable
changeset 26838 47dd34f2e727
parent 26837 33894facc180
child 26852 3fb36dec1727
permissions -rw-r--r--
i18n: look translation of both "DEPRECATED" and "(DEPRECATED)" up Since 44cc9f63a2f1, deprecated commands, options and so on are detected by "(DEPRECATED)" instead of "DEPRECATED". "hg.pot" generated from recent source files doesn't contain msgid "DEPRECATED", and looking the translation of "DEPRECATED" up in up-to-date *.po files works incorrectly. But on the other hand, there are still old *.po files, which contain msgid "DEPRECATED" but not "(DEPRECATED)". Looking the translation of "(DEPRECATED)" up in such old *.po files also works incorrectly. This patch resolves this problem by looking translation of both "DEPRECATED" and "(DEPRECATED)" up. This should work correctly, because previous patch makes "deprecated" checker be applied only on translations, of which msgid contains exact "(DEPRECATED)" string. 'p.msgstr' examination in 'deprecatedsetup()' is needed to ignore untranslated entries. This also makes 'deprecatedpe.msgstr' examination in 'deprecated()' meaningless.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     4
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     5
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
     6
import re
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
     7
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
     8
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
     9
checkers = []
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    10
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    11
def scanner():
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    12
    def decorator(func):
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    13
        scanners.append(func)
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    14
        return func
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    15
    return decorator
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    16
22203
35c2ea4ca26f cleanup: rename check-translation.py checker function - don't hide global var
Mads Kiilerich <madski@unity3d.com>
parents: 20515
diff changeset
    17
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
    18
    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
    19
        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
    20
            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
    21
        else:
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    22
            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
    23
        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
    24
        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
    25
        return func
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    26
    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
    27
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    28
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
    29
    """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
    30
    """
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    31
    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
    32
        return
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    33
    # 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
    34
    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
    35
    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
    36
        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
    37
            return
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    38
    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
    39
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    40
####################
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    41
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    42
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
    43
    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
    44
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    45
@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
    46
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
    47
    """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
    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
    >>> 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
    50
    ...     msgid ='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
    51
    ...     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
    52
    >>> 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
    53
    True
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    54
    >>> for e in promptchoice(pe): print e
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    55
    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
    56
    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
    57
    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
    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
    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
    60
    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
    61
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    62
    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
    63
        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
    64
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
    65
    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
    66
    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
    67
        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
    68
    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
    69
        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
    70
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    71
deprecatedpe = None
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    72
@scanner()
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    73
def deprecatedsetup(pofile):
26838
47dd34f2e727 i18n: look translation of both "DEPRECATED" and "(DEPRECATED)" up
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26837
diff changeset
    74
    pes = [p for p in pofile
47dd34f2e727 i18n: look translation of both "DEPRECATED" and "(DEPRECATED)" up
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26837
diff changeset
    75
           if ((p.msgid == 'DEPRECATED' or p.msgid == '(DEPRECATED)') and
47dd34f2e727 i18n: look translation of both "DEPRECATED" and "(DEPRECATED)" up
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26837
diff changeset
    76
               p.msgstr)]
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    77
    if len(pes):
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    78
        global deprecatedpe
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    79
        deprecatedpe = pes[0]
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    80
26837
33894facc180 i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26277
diff changeset
    81
@fatalchecker(r'\(DEPRECATED\)')
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    82
def deprecated(pe):
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    83
    """Check for DEPRECATED
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    84
    >>> ped = polib.POEntry(
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    85
    ...     msgid = 'DEPRECATED',
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    86
    ...     msgstr= 'DETACERPED')
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    87
    >>> deprecatedsetup([ped])
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    88
    >>> pe = polib.POEntry(
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    89
    ...     msgid = 'Something (DEPRECATED)',
26277
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    90
    ...     msgstr= 'something (DEPRECATED)')
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    91
    >>> match(deprecated, pe)
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    92
    True
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    93
    >>> for e in deprecated(pe): print e
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    94
    >>> pe = polib.POEntry(
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    95
    ...     msgid = 'Something (DEPRECATED)',
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    96
    ...     msgstr= 'something (DETACERPED)')
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    97
    >>> match(deprecated, pe)
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
    98
    True
26277
ad4d6c7aea6a tests: add more doctests for check-translation deprecated
timeless@mozdev.org
parents: 26276
diff changeset
    99
    >>> for e in deprecated(pe): print e
26261
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)',
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   102
    ...     msgstr= 'something')
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   103
    >>> match(deprecated, pe)
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   104
    True
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   105
    >>> for e in deprecated(pe): print e
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   106
    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
   107
    >>> pe = polib.POEntry(
33894facc180 i18n: fix regexp pattern to detect translation for DEPRECATED
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26277
diff changeset
   108
    ...     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
   109
    ...     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
   110
    >>> match(deprecated, pe)
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   111
    """
26276
93395bee98ba tests: cleanup check-translation deprecated
timeless@mozdev.org
parents: 26261
diff changeset
   112
    if not ('(DEPRECATED)' in pe.msgstr or
26838
47dd34f2e727 i18n: look translation of both "DEPRECATED" and "(DEPRECATED)" up
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26837
diff changeset
   113
            (deprecatedpe and
26276
93395bee98ba tests: cleanup check-translation deprecated
timeless@mozdev.org
parents: 26261
diff changeset
   114
             deprecatedpe.msgstr in pe.msgstr)):
93395bee98ba tests: cleanup check-translation deprecated
timeless@mozdev.org
parents: 26261
diff changeset
   115
        yield "msgstr inconsistently translated (DEPRECATED)"
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   116
20152
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   117
####################
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   118
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   119
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
   120
    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
   121
20514
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   122
@warningchecker()
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   123
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
   124
    """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
   125
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   126
    >>> 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
   127
    ...     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
   128
    ...     msgstr='ends with ::')
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   129
    >>> for e in taildoublecolons(pe): print e
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   130
    >>> 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
   131
    ...     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
   132
    ...     msgstr='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
   133
    >>> for e in taildoublecolons(pe): print e
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   134
    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
   135
    >>> 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
   136
    ...     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
   137
    ...     msgstr='ends with ::')
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   138
    >>> for e in taildoublecolons(pe): print e
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   139
    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
   140
    """
410c80539c5c i18n: check equality of tail '::'-ness between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20164
diff changeset
   141
    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
   142
        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
   143
20515
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   144
@warningchecker()
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   145
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
   146
    """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
   147
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   148
    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
   149
    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
   150
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   151
    >>> 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
   152
    ...     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
   153
    ...     msgstr='  narrowed indentation')
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   154
    >>> for e in indentation(pe): print e
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   155
    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
   156
    """
6afbfb9b1af1 i18n: check equality of initial indentation between msgid and msgstr
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20514
diff changeset
   157
    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
   158
    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
   159
    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
   160
        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
   161
20152
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   162
####################
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   163
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   164
def check(pofile, fatal=True, warning=False):
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   165
    targetlevel = { 'fatal': fatal, 'warning': warning }
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   166
    targetcheckers = [(checker, level)
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   167
                      for checker, level in checkers
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   168
                      if targetlevel[level]]
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   169
    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
   170
        return []
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   171
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   172
    detected = []
26261
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   173
    for checker in scanners:
8fb92ff63ccf tests: check for inconsistently translated DEPRECATED
timeless@mozdev.org
parents: 22203
diff changeset
   174
        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
   175
    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
   176
        errors = []
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   177
        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
   178
            if 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
   179
                errors.extend((level, checker.__name__, error)
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   180
                              for error in 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
   181
        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
   182
            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
   183
    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
   184
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   185
########################################
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   186
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 __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
   188
    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
   189
    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
   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
    optparser = optparse.OptionParser("""%prog [options] pofile ...
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   192
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   193
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
   194
'*.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
   195
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   196
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
   197
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   198
    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
   199
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   200
"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
   201
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
   202
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   203
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
   204
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
   205
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
   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
    # 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
   208
    msgid = "....."
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   209
    msgstr = "....."
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   210
""")
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   211
    optparser.add_option("", "--warning",
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   212
                         help="show also warning level problems",
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   213
                         action="store_true")
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   214
    optparser.add_option("", "--doctest",
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   215
                         help="run doctest of this tool, instead of check",
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   216
                         action="store_true")
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   217
    (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
   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
    if options.doctest:
20164
1ddf4409229f tests: fix missing import in check-translations
Matt Mackall <mpm@selenic.com>
parents: 20158
diff changeset
   220
        import os
20158
209e04a06467 tests: fix Mac doctest escape code garbage for check-translations
Matt Mackall <mpm@selenic.com>
parents: 20152
diff changeset
   221
        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
   222
            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
   223
        import doctest
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   224
        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
   225
        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
   226
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   227
    # replace polib._POFileParser to show linenum of problematic msgstr
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   228
    class ExtPOFileParser(polib._POFileParser):
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   229
        def process(self, symbol, linenum):
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   230
            super(ExtPOFileParser, self).process(symbol, linenum)
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   231
            if symbol == 'MS': # msgstr
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   232
                self.current_entry.linenum = linenum
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   233
    polib._POFileParser = ExtPOFileParser
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   234
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   235
    detected = []
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   236
    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
   237
    for f in args:
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   238
        detected.extend((f, 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
   239
                        for pe, errors in check(polib.pofile(f),
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   240
                                                warning=warning))
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   241
    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
   242
        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
   243
            for level, checker, error in errors:
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   244
                sys.stderr.write('%s:%d:%s(%s): %s\n'
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   245
                                 % (f, pe.linenum, level, checker, error))
84939b728749 i18n: add the tool to check Mercurial specific translation problems in *.po
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
diff changeset
   246
        sys.exit(1)