From 20148acff3fba6cdbd98053a61d96caa523f0534 Mon Sep 17 00:00:00 2001 From: WhatDidYouExpect <89535984+WhatDidYouExpect@users.noreply.github.com> Date: Mon, 7 Jul 2025 00:05:06 +0200 Subject: [PATCH] Add checks to see what key is missing from what locale --- .gitignore | 1 + validate_locales.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 validate_locales.py diff --git a/.gitignore b/.gitignore index 0407297..6ef4036 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ __pycache__ locales/ locales/it.json locales/en.json +translation_report.txt diff --git a/validate_locales.py b/validate_locales.py new file mode 100644 index 0000000..b89d1d7 --- /dev/null +++ b/validate_locales.py @@ -0,0 +1,50 @@ +import time +from main import translations, LOCALE, find_locales_dirs, module_dir, working_dir, RESET +from main import load_translations + +YELLOW = "\033[93m" + +def check_missing_translations(): + + load_translations() + + if "en" not in translations: + print("English translations (en.json) missing from assets/locales. Exiting.") + return + + en_keys = set(translations["en"].keys()) + total_keys = len(en_keys) + + report_lines = [] + report_lines.append(f"Total keys in English locale: {total_keys}\n") + + for locale, trans_dict in translations.items(): + if locale in ("en", "empty"): + continue + locale_keys = set(trans_dict.keys()) + missing_keys = en_keys - locale_keys + missing_count = len(missing_keys) + percent_missing = (missing_count / total_keys) * 100 if total_keys > 0 else 0 + + if missing_count > 0: + print(f"{YELLOW}Warning: {missing_count}/{total_keys} keys missing in locale '{locale}' ({percent_missing:.1f}%)!{RESET}") + for key in sorted(missing_keys): + print(f" - {key}") + time.sleep(1) + else: + print(f"All translation keys present for locale: {locale}") + + report_lines.append(f"Locale: {locale}\n") + report_lines.append(f"Missing keys ({missing_count}/{total_keys}): {percent_missing:.1f}%\n") + if missing_count > 0: + for key in sorted(missing_keys): + report_lines.append(f" - {key}\n") + report_lines.append("\n") + + with open("translation_report.txt", "w", encoding="utf-8") as f: + f.writelines(report_lines) + + print("\nTranslation report written to translation_report.txt") + +if __name__ == "__main__": + check_missing_translations()