Comments
Patch
@@ -0,0 +1,69 @@
+import polib
+import sys
+import re
+
+rstsection=re.compile(r"::\s*(?:\n|$)")
+breakafter=re.compile(r"\n$")
+replacements=re.compile("%\d*\.?\d*[dfirs]")
+paragraphs=re.compile(r"\n\n+")
+
+verbose = False
+stats = None
+tests = set()
+
+def report(fault, key):
+ global limit
+ global tests
+ if tests and not fault in tests:
+ return
+ if not fault in stats:
+ stats[fault] = 0
+ stats[fault] += 1
+ if not verbose:
+ return
+ print("%s? %s" % (fault, key))
+
+def main():
+ global stats
+ global tests
+ global verbose
+ limitingtest = False
+ for f in sys.argv[1:]:
+ stats = {}
+ if f == '-v':
+ verbose = True
+ continue
+ if f == '-t':
+ limitingtest = True
+ continue
+ if limitingtest:
+ tests.add(f)
+ limitingtest = False
+ continue
+ try:
+ po = polib.pofile(f)
+ except IOError:
+ print("Unhandled 'po' file: %s" % f)
+ continue
+ for record in po:
+ key = record.msgid
+ value = record.msgstr
+ # Matching translation or Untranslated
+ if key == value or value == '':
+ continue
+ # More sections in translation than in the original
+ if len(rstsection.findall(key)) > len(rstsection.findall(value)):
+ report("rstsection", key)
+ # Original and Translation should both end in a break or not end in a break
+ if (breakafter.search(key) != None) != (breakafter.search(value) != None):
+ report("breakafter", key)
+ # Original and Translation should use all of the same variable substitutions
+ if "".join(sorted(replacements.findall(key))) != "".join(sorted(replacements.findall(value))):
+ report("replacements", key)
+ if len(paragraphs.findall(key)) != len(paragraphs.findall(value)):
+ report("paragraphs", key)
+ if stats:
+ errors = ["%s: %s" % (k, stats[k]) for k in sorted(stats)]
+ print("%s errors: %s" % (f, ", ".join(errors)))
+
+main()