changeset 26261:8fb92ff63ccf

tests: check for inconsistently translated DEPRECATED Mercurial expects DEPRECATED to be translated consistently, not doing that breaks Mercurial.
author timeless@mozdev.org
date Thu, 17 Sep 2015 07:49:18 -0400
parents 3aa1aabbe94d
children 3e79ec0ba589
files i18n/check-translation.py
diffstat 1 files changed, 43 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/i18n/check-translation.py	Thu Sep 17 07:33:21 2015 -0400
+++ b/i18n/check-translation.py	Thu Sep 17 07:49:18 2015 -0400
@@ -5,8 +5,15 @@
 import polib
 import re
 
+scanners = []
 checkers = []
 
+def scanner():
+    def decorator(func):
+        scanners.append(func)
+        return func
+    return decorator
+
 def levelchecker(level, msgidpat):
     def decorator(func):
         if msgidpat:
@@ -61,6 +68,40 @@
     if [c for c, i in indices if len(c) == i + 1]:
         yield "msgstr has invalid '&' followed by none"
 
+deprecatedpe = None
+@scanner()
+def deprecatedsetup(pofile):
+    pes = [p for p in pofile if p.msgid == 'DEPRECATED']
+    if len(pes):
+        global deprecatedpe
+        deprecatedpe = pes[0]
+
+@fatalchecker('(DEPRECATED)')
+def deprecated(pe):
+    """Check for DEPRECATED
+    >>> ped = polib.POEntry(
+    ...     msgid = 'DEPRECATED',
+    ...     msgstr= 'DETACERPED')
+    >>> deprecatedsetup([ped])
+    >>> pe = polib.POEntry(
+    ...     msgid = 'Something (DEPRECATED)',
+    ...     msgstr= 'something (DETACERPED)')
+    >>> match(deprecated, pe)
+    True
+    >>> pe = polib.POEntry(
+    ...     msgid = 'Something (DEPRECATED)',
+    ...     msgstr= 'something')
+    >>> match(deprecated, pe)
+    True
+    >>> for e in deprecated(pe): print e
+    msgstr inconsistently translated (DEPRECATED)
+    """
+    global deprecatedpe
+    if not '(DEPRECATED)' in pe.msgstr:
+        if not (deprecatedpe and deprecatedpe.msgstr
+                and deprecatedpe.msgstr in pe.msgstr):
+            yield "msgstr inconsistently translated (DEPRECATED)"
+
 ####################
 
 def warningchecker(msgidpat=None):
@@ -117,6 +158,8 @@
         return []
 
     detected = []
+    for checker in scanners:
+        checker(pofile)
     for pe in pofile.translated_entries():
         errors = []
         for checker, level in targetcheckers: