Skip to content

Commit

Permalink
Make check_translations workflow check for accidentally untranslated …
Browse files Browse the repository at this point in the history
…strings
  • Loading branch information
Alexander01998 committed Dec 23, 2024
1 parent 853d3f3 commit 8d6276c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check_translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ jar {
from("LICENSE") {
rename {"${it}_${base.archivesName.get()}"}
}

exclude("intentionally_untranslated.json")
}

spotless {
Expand Down
36 changes: 36 additions & 0 deletions scripts/check_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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__":
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/intentionally_untranslated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"de_de": [
"key.wurst.zoom"
],
"fr_fr": [
"key.wurst.zoom",
"button.wurst.nochatreports.signatures_status"
]
}

0 comments on commit 8d6276c

Please sign in to comment.