diff options
author | Patrick Griffis <tingping@tingping.se> | 2018-04-03 16:08:27 -0400 |
---|---|---|
committer | Patrick Griffis <tingping@tingping.se> | 2018-04-03 16:08:27 -0400 |
commit | 5cd70622aaabc0419cc0b547808f09221530f0fc (patch) | |
tree | 6de8743d76a34d41464ed1ac5de279ac25790306 /po/validate-textevent-translations | |
parent | 5ca767f7f881f480de90882233ed833846bd8a3d (diff) |
Validate all translations contain valid text events
Diffstat (limited to 'po/validate-textevent-translations')
-rwxr-xr-x | po/validate-textevent-translations | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/po/validate-textevent-translations b/po/validate-textevent-translations new file mode 100755 index 00000000..c9c6e6a3 --- /dev/null +++ b/po/validate-textevent-translations @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import os +import re +import sys + +ret = 0 + + +def validate_translation(input, translation): + if not translation: + return True + + if re.findall(r'(?:(?<!%)%[^%OCRUHBIH]|\$[^at1234])', translation): + print('Translation includes invalid formatting:', translation) + + in_vars = re.findall(r'(\$(?:\d|t))', input) + if not all(var in translation for var in in_vars): + print('Translation does not contain all variables:', translation) + return False + + in_ascii = re.findall(r'\$a(\d{3})', translation) + if any(int(i) > 256 for i in in_ascii): + print('Translation contains invalid ascii value:') + return False + + # We could try to validate colors but that is pretty flexible + return True + + +def validate_language(path): + global ret + + print('Validating', path) + + with open(path, 'r') as f: + in_event = False + event_input = '' + + for line in f: + if 'textevents.h' in line: + in_event = True + elif in_event is False: + continue + elif line.startswith('msgid'): + event_input = line[7:-2] + elif line.startswith('msgstr'): + if not validate_translation(event_input, line[8:-2]): + ret = 1 + in_event = False + elif line == '\n': + print('Failed to find translation for', event_input) + in_event = False + + +with open(sys.argv[1], 'r') as linguas: + for lang in linguas: + path = os.path.join(sys.argv[2], lang.strip() + '.po') + validate_language(path) + +sys.exit(ret) |