From 8d6276c262caec65d657e33114282d49595979ba Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:55:21 +0100 Subject: [PATCH] Make check_translations workflow check for accidentally untranslated strings --- .github/workflows/check_translations.yml | 2 ++ build.gradle | 2 ++ scripts/check_translations.py | 36 +++++++++++++++++++ .../resources/intentionally_untranslated.json | 9 +++++ 4 files changed, 49 insertions(+) create mode 100644 src/main/resources/intentionally_untranslated.json diff --git a/.github/workflows/check_translations.yml b/.github/workflows/check_translations.yml index 1a300754e7..e20293cab7 100644 --- a/.github/workflows/check_translations.yml +++ b/.github/workflows/check_translations.yml @@ -8,9 +8,11 @@ on: - "**" paths: - "src/main/resources/assets/wurst/translations/**.json" + - "src/main/resources/intentionally_untranslated.json" pull_request: paths: - "src/main/resources/assets/wurst/translations/**.json" + - "src/main/resources/intentionally_untranslated.json" workflow_dispatch: jobs: diff --git a/build.gradle b/build.gradle index 0f81e6eee9..008f2d8c32 100644 --- a/build.gradle +++ b/build.gradle @@ -121,6 +121,8 @@ jar { from("LICENSE") { rename {"${it}_${base.archivesName.get()}"} } + + exclude("intentionally_untranslated.json") } spotless { diff --git a/scripts/check_translations.py b/scripts/check_translations.py index bf648c01fc..59f6c339d6 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -30,6 +30,41 @@ def check_extra_keys(en_us: dict, translations: dict): raise Exception("Found extra keys in one or more translation files, see summary") +def check_untranslated_strings(en_us: dict, translations: dict): + """Check if any translation files contain untranslated strings.""" + untranslated_strings_found = False + intentionally_untranslated = util.read_json_file( + Path("src") / "main" / "resources" / "intentionally_untranslated.json" + ) + + for lang, data in translations.items(): + untranslated_strings = set() + for key, value in data.items(): + if value == en_us[key]: + if lang in intentionally_untranslated and key in intentionally_untranslated[lang]: + continue + untranslated_strings.add(key) + if untranslated_strings: + untranslated_strings_found = True + util.add_github_summary( + f"⚠ {lang}.json contains strings that are identical to en_us.json ({len(untranslated_strings)} found):" + ) + for key in untranslated_strings: + util.add_github_summary(f"- {key}: {en_us[key]}") + util.add_github_summary( + "\nIf this is intentional, add the affected key(s) to intentionally_untranslated.json:" + ) + util.add_github_summary("```json") + util.add_github_summary(f' "{lang}": [') + for key in untranslated_strings: + util.add_github_summary(f' "{key}"') + util.add_github_summary(" ]") + util.add_github_summary("```") + + if untranslated_strings_found: + raise Exception("Found untranslated strings in one or more translation files, see summary") + + def main(): en_us = util.read_json_file(translations_dir / "en_us.json") translations = {} @@ -41,6 +76,7 @@ def main(): show_translation_stats(en_us, translations) check_extra_keys(en_us, translations) + check_untranslated_strings(en_us, translations) if __name__ == "__main__": diff --git a/src/main/resources/intentionally_untranslated.json b/src/main/resources/intentionally_untranslated.json new file mode 100644 index 0000000000..97dc8038b7 --- /dev/null +++ b/src/main/resources/intentionally_untranslated.json @@ -0,0 +1,9 @@ +{ + "de_de": [ + "key.wurst.zoom" + ], + "fr_fr": [ + "key.wurst.zoom", + "button.wurst.nochatreports.signatures_status" + ] +}