|
| 1 | +from glob import glob |
| 2 | +from json import load |
| 3 | +from os import path |
| 4 | + |
| 5 | +ALL_PATH = "../../website/public/locales/**/*.json" |
| 6 | +DIR = path.dirname(__file__) |
| 7 | +EN_PATH = "../../website/public/locales/en/*.json" |
| 8 | + |
| 9 | + |
| 10 | +def get_not_translated(en_json, translation_json, parent_key=None): |
| 11 | + not_translated = [] |
| 12 | + for key in en_json.keys(): |
| 13 | + if key in translation_json and translation_json[key] == en_json[key]: |
| 14 | + not_translated.append(("{0}.{1}".format(parent_key, key) if parent_key else key)) |
| 15 | + elif isinstance(en_json[key], dict): |
| 16 | + not_translated.extend(get_not_translated(en_json[key], translation_json[key], key)) |
| 17 | + return not_translated |
| 18 | + |
| 19 | + |
| 20 | +def get_missing(en_json, translation_json): |
| 21 | + return [key for key in en_json.keys() if key not in translation_json] |
| 22 | + |
| 23 | + |
| 24 | +def print_result(missing, not_translated, file): |
| 25 | + if len(missing): |
| 26 | + print("[{0}] - missing: {1} {2}".format(path.basename(path.dirname(file)), path.basename(file), missing)) |
| 27 | + if len(not_translated): |
| 28 | + print( |
| 29 | + "[{0}] - potentially untranslated: {1} {2}".format( |
| 30 | + path.basename(path.dirname(file)), path.basename(file), not_translated |
| 31 | + ) |
| 32 | + ) |
| 33 | + |
| 34 | + |
| 35 | +def audit(file, en_file): |
| 36 | + en_json = load(open(en_file)) |
| 37 | + translation_json = load(open(file)) |
| 38 | + print_result(get_missing(en_json, translation_json), get_not_translated(en_json, translation_json), file) |
| 39 | + |
| 40 | + |
| 41 | +def main(): |
| 42 | + for en_file in glob(path.join(DIR, EN_PATH)): |
| 43 | + for file in glob(path.join(DIR, ALL_PATH)): |
| 44 | + if path.basename(en_file) == path.basename(file) and file != en_file: |
| 45 | + audit(file, en_file) |
| 46 | + |
| 47 | + |
| 48 | +if __name__ == "__main__": |
| 49 | + main() |
0 commit comments