From 3c695c4a15cef269c8259413ddce70d57aee7dc2 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 21 Jan 2014 19:30:24 +0100 Subject: [PATCH] Improve the check_trans script by using Supybot's .po(t) parser. The previous method matched line by line, which broke for msgmerge alternative (poedit\!\!\!) that changes line breaks. --- sandbox/check_trans.py | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/sandbox/check_trans.py b/sandbox/check_trans.py index feffd6476..c0914c714 100755 --- a/sandbox/check_trans.py +++ b/sandbox/check_trans.py @@ -3,8 +3,11 @@ import os import sys import glob +import operator import subprocess +from supybot.i18n import parse + def main(): directory = sys.argv[1] if directory == '--core': @@ -63,27 +66,11 @@ def checkPlugin(pluginPath): def checkTranslation(pot, po): checking = False - for potLine in pot: - if not checking and potLine.startswith('msgid'): - checking = True - while True: - poLine = po.readline() - if poLine == '': # EOF - return False - if poLine.startswith('msgid'): - if poLine == potLine: - break - else: - return False - continue - elif checking and potLine.startswith('msgstr'): - checking = False - - if checking: - poLine = po.readline() - if potLine != poLine: - return False - return True + pot = set(map(operator.itemgetter(0), parse(pot))) + po = set(map(operator.itemgetter(0), parse(po))) + diff = filter(lambda x:x not in po, pot) + print(diff) + return not bool(diff) if __name__ == '__main__': main()