From 6b9d6b6be5c2d4da871384dc57a54d6a15689b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 25 Feb 2016 13:53:53 +0000 Subject: [PATCH] Add a py script to check for bad string formats Lint finds these, but it's very slow and currently we're not taking lint errors as fatal. So for now this script will be useful, as nearly every time I pull from weblate there are at least a couple of these. --- F-Droid/tools/check-string-format.py | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 F-Droid/tools/check-string-format.py diff --git a/F-Droid/tools/check-string-format.py b/F-Droid/tools/check-string-format.py new file mode 100755 index 000000000..867090385 --- /dev/null +++ b/F-Droid/tools/check-string-format.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python2 + +# Remove extra translations + +import glob +import os +import sys +import re +from xml.etree import ElementTree + +formatRe = re.compile(r'(%%|%[^%](\$.)?)') + +validFormatRe = re.compile(r'^(%%|%[sd]|%[0-9]\$[sd])$') + +count = 0 + +for d in glob.glob(os.path.join('res', 'values-*')): + + str_path = os.path.join(d, 'strings.xml') + if not os.path.exists(str_path): + continue + + tree = ElementTree.parse(str_path) + root = tree.getroot() + + for e in root.findall('.//string'): + for m in formatRe.finditer(e.text): + s = m.group(0) + if validFormatRe.match(s): + continue + count += 1 + print('%s: Invalid format "%s" in "%s"' % (str_path, s, e.text)) + +if count > 0: + print("%d misformatted strings found!" % count) + sys.exit(1) +