[PATCH 2 of 2] tests: check for inconsistently translated DEPRECATED
timeless at mozdev.org
timeless at mozdev.org
Thu Sep 17 16:11:31 CDT 2015
# HG changeset patch
# User timeless at 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.
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
+ at scanner()
+def deprecatedsetup(pofile):
+ pes = [p for p in pofile if p.msgid == 'DEPRECATED']
+ if len(pes):
+ global deprecatedpe
+ deprecatedpe = pes[0]
+
+ at 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:
More information about the Mercurial-devel
mailing list