Skip to content
Snippets Groups Projects
Unverified Commit 64f086c0 authored by Paul B's avatar Paul B
Browse files

i18n: adds a check on missing translation keys in locale/*.json file

This commit adds a script to check all keys from translation files to
make sure no missing keys / no translation files are incorrect.

Even if missing keys should not happen (because we use a script to add
keys automatically) this script made helped to understand that all
three `ar`, `eo` and `fr_FR` translation files were completly off
compared to the `en.json` file.

I believe we can safely delete `ar`, `eo` and `fr_FR` locales from
Zanata (because those languages are not set in the ALLOWED_LANGUAGES
config array). ⚠️ this needs to be check in the production `config.php`
file ⚠️.

Deleting the `fr_FR` locale file should solve both !358 and #395

closes !358 #395
parent 80336b43
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,11 @@ test: ...@@ -17,6 +17,11 @@ test:
paths: paths:
- vendor/ - vendor/
check:missing:trads:
stage: test
script:
- ./scripts/check-translations.py
# check-trad: # check-trad:
# stage: test # stage: test
# allow_failure: true # allow_failure: true
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/usr/bin/env python
import json
import glob
def get_all_keys(jsons_dict):
all_keys = set()
for json_dict in jsons_dict.values():
all_keys |= flatten_keys(json_dict)
return all_keys
def flatten_keys(json_dict):
all_keys = set()
for key in json_dict.keys():
el = json_dict[key]
if isinstance(el, dict):
flatten = flatten_keys(el)
for flat_key in flatten:
all_keys.add("%s.%s" % (key, flat_key))
else:
all_keys.add(key)
return all_keys
def check_files_share_same_keys(all_keys, jsons):
exit_code = 0
for locale in jsons.keys():
difference = all_keys - flatten_keys(jsons[locale])
if bool(difference):
print("%s has missing translation keys:" % (locale))
for el in difference:
print(" - %s" % (el))
exit_code = 1
return exit_code
def main():
locales_dir = "locale/*.json"
jsons = {}
for json_file in glob.iglob(locales_dir):
with open(json_file) as f:
jsons[json_file] = json.load(f)
all_keys = get_all_keys(jsons)
return check_files_share_same_keys(all_keys, jsons)
main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment