Patchwork [2,of,2] tests: check for inconsistently translated DEPRECATED

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 17, 2015, 9:11 p.m.
Message ID <aaccdd4fb0ff0809c968.1442524291@waste.org>
Download mbox | patch
Permalink /patch/10528/
State Accepted
Headers show

Comments

timeless@mozdev.org - Sept. 17, 2015, 9:11 p.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1442490558 14400
#      Thu Sep 17 07:49:18 2015 -0400
# Node ID aaccdd4fb0ff0809c968a00f75a1b34d05bd7992
# Parent  4da73f01675814e817df06f01d74fbbf4ce0e5c7
tests: check for inconsistently translated DEPRECATED

Mercurial expects DEPRECATED to be translated consistently,
not doing that breaks Mercurial.
Pierre-Yves David - Sept. 17, 2015, 9:29 p.m.
On 09/17/2015 02:11 PM, timeless@mozdev.org wrote:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1442490558 14400
> #      Thu Sep 17 07:49:18 2015 -0400
> # Node ID aaccdd4fb0ff0809c968a00f75a1b34d05bd7992
> # Parent  4da73f01675814e817df06f01d74fbbf4ce0e5c7
> tests: check for inconsistently translated DEPRECATED

Pushed to the clowncopter, thanks.
check-code sent his regards.

Patch

diff --git a/i18n/check-translation.py b/i18n/check-translation.py
--- a/i18n/check-translation.py
+++ b/i18n/check-translation.py
@@ -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,39 @@ 
     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 or not deprecatedpe.msgstr or not deprecatedpe.msgstr in pe.msgstr:
+            yield "msgstr inconsistently translated (DEPRECATED)"
+
 ####################
 
 def warningchecker(msgidpat=None):
@@ -117,6 +157,8 @@ 
         return []
 
     detected = []
+    for checker in scanners:
+        checker(pofile)
     for pe in pofile.translated_entries():
         errors = []
         for checker, level in targetcheckers: