# HG changeset patch # User timeless@mozdev.org # Date 1442490558 14400 # Node ID 8fb92ff63ccfc3202c17468baf065cc63b3fc1bd # Parent 3aa1aabbe94d6d5bc4a096add7b4d744b9a8cf77 tests: check for inconsistently translated DEPRECATED Mercurial expects DEPRECATED to be translated consistently, not doing that breaks Mercurial. diff -r 3aa1aabbe94d -r 8fb92ff63ccf i18n/check-translation.py --- 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: