From 35e8c871ba5a2880cb2086f0873324ca44c3ce3d Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 22 Dec 2024 23:39:30 +0100 Subject: [PATCH 01/12] Add announce_backport option to publish workflow --- .github/workflows/publish.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 298f3c6eaf..258d6af6f5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,6 +30,11 @@ on: required: true type: boolean default: false + announce_backport: + description: "Announce as a backport on WurstForum" + required: false + type: boolean + default: false jobs: publish: @@ -96,3 +101,4 @@ jobs: -f wurst_version="$WURST_VERSION" \ -f mc_version="$MC_VERSION" \ -f fapi_version="$FAPI_VERSION" + -f announce=${{ inputs.announce_backport }} From 3a06d016ccb15eb46e46beb8f00cc542234cf7f9 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Sun, 22 Dec 2024 23:55:59 +0100 Subject: [PATCH 02/12] Make publish workflow wait for website update and fail if that fails --- .github/workflows/publish.yml | 44 ++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 258d6af6f5..a074ba4786 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -87,18 +87,44 @@ jobs: GITHUB_TOKEN: ${{ secrets.OLD_MCX_PUBLISH_TOKEN }} run: ./gradlew github --stacktrace - - name: Trigger website update + - name: Build website update inputs + id: website_inputs if: ${{ inputs.update_website }} - env: - GH_TOKEN: ${{ secrets.WURSTCLIENT_NET_PUBLISH_TOKEN }} run: | MOD_VERSION=$(grep "mod_version" gradle.properties | cut -d'=' -f2 | tr -d ' \r') WURST_VERSION=$(echo "$MOD_VERSION" | sed 's/^v//' | sed 's/-MC.*$//') MC_VERSION=$(grep "minecraft_version" gradle.properties | cut -d'=' -f2 | tr -d ' \r') FAPI_VERSION=$(grep "fabric_version" gradle.properties | cut -d'=' -f2 | tr -d ' \r') - gh workflow run add_wurst_port.yml \ - -R Wurst-Imperium/WurstClient.net \ - -f wurst_version="$WURST_VERSION" \ - -f mc_version="$MC_VERSION" \ - -f fapi_version="$FAPI_VERSION" - -f announce=${{ inputs.announce_backport }} + JSON_STRING=$(cat << EOF + { + "wurst_version": "$WURST_VERSION", + "mc_version": "$MC_VERSION", + "fapi_version": "$FAPI_VERSION", + "announce": "${{ inputs.announce_backport }}" + } + EOF + ) + # Convert to single line and escape quotes + echo "json=${JSON_STRING//$'\n'/}" >> "$GITHUB_OUTPUT" + + - name: Trigger website update + id: website_dispatch + if: ${{ inputs.update_website }} + uses: codex-/return-dispatch@v2 + with: + token: ${{ secrets.WURSTCLIENT_NET_PUBLISH_TOKEN }} + owner: Wurst-Imperium + repo: WurstClient.net + ref: gh-pages + workflow: add_wurst_port.yml + workflow_inputs: ${{ steps.website_inputs.outputs.json }} + + - name: Wait for website update to finish (run ${{ steps.website_dispatch.outputs.run_id }}) + if: ${{ inputs.update_website }} + uses: codex-/await-remote-run@v1 + with: + token: ${{ secrets.WURSTCLIENT_NET_PUBLISH_TOKEN }} + owner: Wurst-Imperium + repo: WurstClient.net + run_id: ${{ steps.website_dispatch.outputs.run_id }} + run_timeout_seconds: 600 # 10 minutes From 6666d08f6abd9f19975c02e4cf7afa58d8dbe3a2 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:01:46 +0100 Subject: [PATCH 03/12] Add workflow to check for translation issues --- .github/workflows/check_translations.yml | 30 +++++++++++++++ .gitignore | 5 ++- scripts/check_translations.py | 47 ++++++++++++++++++++++++ scripts/util.py | 17 +++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check_translations.yml create mode 100644 scripts/check_translations.py create mode 100644 scripts/util.py diff --git a/.github/workflows/check_translations.yml b/.github/workflows/check_translations.yml new file mode 100644 index 0000000000..1a300754e7 --- /dev/null +++ b/.github/workflows/check_translations.yml @@ -0,0 +1,30 @@ +name: Check Translations + +on: + push: + branches-ignore: + - "dependabot/**" + tags-ignore: + - "**" + paths: + - "src/main/resources/assets/wurst/translations/**.json" + pull_request: + paths: + - "src/main/resources/assets/wurst/translations/**.json" + workflow_dispatch: + +jobs: + check_translations: + runs-on: ubuntu-latest + steps: + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Python 3.12 + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Run check_translations.py + run: python scripts/check_translations.py diff --git a/.gitignore b/.gitignore index 5eb7947162..5120bab51e 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,7 @@ remappedSrc/ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* -desktop.ini \ No newline at end of file +# python +*.pyc + +desktop.ini diff --git a/scripts/check_translations.py b/scripts/check_translations.py new file mode 100644 index 0000000000..e358bfd4ff --- /dev/null +++ b/scripts/check_translations.py @@ -0,0 +1,47 @@ +import util +from pathlib import Path + +translations_dir = Path("src") / "main" / "resources" / "assets" / "wurst" / "translations" + + +def show_translation_stats(en_us: dict, translations: dict): + """Render a table of the current translation progress for each language.""" + util.add_github_summary("| Language | Translated | % |") + util.add_github_summary("| --- | --- | --- |") + util.add_github_summary(f"| en_us | {len(en_us)} | 100.00% |") + for lang, data in translations.items(): + util.add_github_summary(f"| {lang} | {len(data)} | {len(data) / len(en_us) * 100:.2f}% |") + util.add_github_summary("") + + +def check_extra_keys(en_us: dict, translations: dict): + """Check if any translation files contain keys that don't exist in the original.""" + extra_keys_found = False + for lang, data in translations.items(): + extra_keys = set(data.keys()) - set(en_us.keys()) + if extra_keys: + extra_keys_found = True + util.add_github_summary( + f"⚠ {lang}.json contains translations that don't exist in en_us.json ({len(extra_keys)} found):" + ) + for key in extra_keys: + util.add_github_summary(f"- {key}") + if extra_keys_found: + raise Exception("Found extra keys in one or more translation files, see summary") + + +def main(): + en_us = util.read_json_file(translations_dir / "en_us.json") + translations = {} + for path in translations_dir.rglob("*.json"): + if path.is_file() and path.name != "en_us.json": + lang = path.name.removesuffix(".json") + data = util.read_json_file(path) + translations[lang] = data + + show_translation_stats(en_us, translations) + check_extra_keys(en_us, translations) + + +if __name__ == "__main__": + main() diff --git a/scripts/util.py b/scripts/util.py new file mode 100644 index 0000000000..7a9ef32f57 --- /dev/null +++ b/scripts/util.py @@ -0,0 +1,17 @@ +import json +import os +from pathlib import Path + + +def read_json_file(path: Path) -> dict: + """Read a JSON data file.""" + return json.loads(path.read_text(encoding="utf-8")) + + +def add_github_summary(summary: str): + """Add a line to the GitHub Actions summary for the current step.""" + if "GITHUB_STEP_SUMMARY" not in os.environ: + print(f"Not running on GHA, would have set summary: {summary}") + return + with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as summary_file: + print(summary, file=summary_file) From 5ef08710dc3dca78b6241bf201f04f0b8c7f566f Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:03:38 +0100 Subject: [PATCH 04/12] Remove outdated AntiBlind translation in zh_hk --- src/main/resources/assets/wurst/translations/zh_hk.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/assets/wurst/translations/zh_hk.json b/src/main/resources/assets/wurst/translations/zh_hk.json index 213fb0cf8b..572e91ce62 100644 --- a/src/main/resources/assets/wurst/translations/zh_hk.json +++ b/src/main/resources/assets/wurst/translations/zh_hk.json @@ -1,7 +1,6 @@ { "description.wurst.hack.anchoraura": "自動放置(可選),充能並引爆重生錨以擊殺你附近嘅實體。", "description.wurst.hack.antiafk": "隨便行,避免被伺服器掛機檢查。", - "OUTDATED.description.wurst.hack.antiblind": "以防盲咗。\n同 OptiFine(高清修復)唔兼容。", "description.wurst.hack.anticactus": "保護你避免受到仙人掌傷害。", "description.wurst.hack.antiknockback": "保護你唔會被其他生物或者玩家推動同埋用劍擊退。", "description.wurst.hack.antispam": "預防存在嘅重復刷屏,改為用計數器顯示。", From 7606fee395674eba1c5a36b94a7c89258442249b Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:09:48 +0100 Subject: [PATCH 05/12] Sort translation files by name to make the table more readable --- scripts/check_translations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_translations.py b/scripts/check_translations.py index e358bfd4ff..bf648c01fc 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -33,7 +33,7 @@ def check_extra_keys(en_us: dict, translations: dict): def main(): en_us = util.read_json_file(translations_dir / "en_us.json") translations = {} - for path in translations_dir.rglob("*.json"): + for path in sorted(translations_dir.rglob("*.json"), key=lambda x: x.name): if path.is_file() and path.name != "en_us.json": lang = path.name.removesuffix(".json") data = util.read_json_file(path) From 340056ca7348830b0a596fe31aaf4fae0b3b6881 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:20:02 +0100 Subject: [PATCH 06/12] Clear inventory again before .copyitem test --- src/main/java/net/wurstclient/test/CopyItemCmdTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/wurstclient/test/CopyItemCmdTest.java b/src/main/java/net/wurstclient/test/CopyItemCmdTest.java index 515a819dc6..550e35899a 100644 --- a/src/main/java/net/wurstclient/test/CopyItemCmdTest.java +++ b/src/main/java/net/wurstclient/test/CopyItemCmdTest.java @@ -20,6 +20,8 @@ public static void testCopyItemCmd() { System.out.println("Testing .copyitem command"); setPerspective(Perspective.THIRD_PERSON_FRONT); + runChatCommand("clear"); + clearChat(); // Put on a golden helmet runChatCommand("item replace entity @s armor.head with golden_helmet"); From 853d3f3fbca2b51a30ba3e455ad17ff487744e13 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:52:07 +0100 Subject: [PATCH 07/12] Print GitHub summary directly if running locally --- scripts/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/util.py b/scripts/util.py index 7a9ef32f57..807fce1405 100644 --- a/scripts/util.py +++ b/scripts/util.py @@ -11,7 +11,7 @@ def read_json_file(path: Path) -> dict: def add_github_summary(summary: str): """Add a line to the GitHub Actions summary for the current step.""" if "GITHUB_STEP_SUMMARY" not in os.environ: - print(f"Not running on GHA, would have set summary: {summary}") + print(summary) return with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as summary_file: print(summary, file=summary_file) From 8d6276c262caec65d657e33114282d49595979ba Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:55:21 +0100 Subject: [PATCH 08/12] 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" + ] +} From 7350bca1bd2d28a198184463c2c1bc45d1b30ab2 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 17:58:48 +0100 Subject: [PATCH 09/12] Add success messages to translation checks --- scripts/check_translations.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/check_translations.py b/scripts/check_translations.py index 59f6c339d6..7348627ff6 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -28,6 +28,7 @@ def check_extra_keys(en_us: dict, translations: dict): util.add_github_summary(f"- {key}") if extra_keys_found: raise Exception("Found extra keys in one or more translation files, see summary") + print("✅ No extra keys found") def check_untranslated_strings(en_us: dict, translations: dict): @@ -63,6 +64,7 @@ def check_untranslated_strings(en_us: dict, translations: dict): if untranslated_strings_found: raise Exception("Found untranslated strings in one or more translation files, see summary") + print("✅ No accidentally untranslated strings found") def main(): From a426e42df7d344099472c335a479221034e33165 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 18:04:51 +0100 Subject: [PATCH 10/12] Add check for order of strings in translation files --- scripts/check_translations.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/scripts/check_translations.py b/scripts/check_translations.py index 7348627ff6..363334dabf 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -67,6 +67,16 @@ def check_untranslated_strings(en_us: dict, translations: dict): print("✅ No accidentally untranslated strings found") +def check_order_of_strings(en_us: dict, translations: dict): + """Check if the strings in each translation file are in the same order as in en_us.json.""" + for lang, data in translations.items(): + en_us_keys_present_in_translation = [key for key in en_us.keys() if key in data.keys()] + translation_keys_present_in_en_us = [key for key in data.keys() if key in en_us.keys()] + if en_us_keys_present_in_translation != translation_keys_present_in_en_us: + raise Exception(f"⚠ The order of strings in {lang}.json is different from en_us.json") + print("✅ The order of strings in each translation file matches en_us.json") + + def main(): en_us = util.read_json_file(translations_dir / "en_us.json") translations = {} @@ -79,6 +89,7 @@ def main(): show_translation_stats(en_us, translations) check_extra_keys(en_us, translations) check_untranslated_strings(en_us, translations) + check_order_of_strings(en_us, translations) if __name__ == "__main__": From c2b702c8312f543acd8419d235c3ab8737e10702 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 19:13:52 +0100 Subject: [PATCH 11/12] Fix success messages going to output instead of GitHub summary --- scripts/check_translations.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/check_translations.py b/scripts/check_translations.py index 363334dabf..3a8904af48 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -28,7 +28,7 @@ def check_extra_keys(en_us: dict, translations: dict): util.add_github_summary(f"- {key}") if extra_keys_found: raise Exception("Found extra keys in one or more translation files, see summary") - print("✅ No extra keys found") + util.add_github_summary("✅ No extra keys found") def check_untranslated_strings(en_us: dict, translations: dict): @@ -64,7 +64,7 @@ def check_untranslated_strings(en_us: dict, translations: dict): if untranslated_strings_found: raise Exception("Found untranslated strings in one or more translation files, see summary") - print("✅ No accidentally untranslated strings found") + util.add_github_summary("✅ No accidentally untranslated strings found") def check_order_of_strings(en_us: dict, translations: dict): @@ -74,7 +74,7 @@ def check_order_of_strings(en_us: dict, translations: dict): translation_keys_present_in_en_us = [key for key in data.keys() if key in en_us.keys()] if en_us_keys_present_in_translation != translation_keys_present_in_en_us: raise Exception(f"⚠ The order of strings in {lang}.json is different from en_us.json") - print("✅ The order of strings in each translation file matches en_us.json") + util.add_github_summary("✅ The order of strings in each translation file matches en_us.json") def main(): From df247004fbb1336ccd19761e012841f75b2d5788 Mon Sep 17 00:00:00 2001 From: Alexander01998 Date: Mon, 23 Dec 2024 20:07:39 +0100 Subject: [PATCH 12/12] Add checks for some other common translation issues --- scripts/check_translations.py | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/scripts/check_translations.py b/scripts/check_translations.py index 3a8904af48..87f8efa1c4 100644 --- a/scripts/check_translations.py +++ b/scripts/check_translations.py @@ -77,6 +77,63 @@ def check_order_of_strings(en_us: dict, translations: dict): util.add_github_summary("✅ The order of strings in each translation file matches en_us.json") +def check_known_issues(en_us: dict, translations: dict): + """Check if any translation files contain known issues.""" + issues_found = False + + # Typos + known_typos = { + "Anchoraura": "AnchorAura", + "Autobuild": "AutoBuild", + "Clickaura": "ClickAura", + "KillAura": "Killaura", + "LegitNuker": "Nuker", + "LegitKillaura": "KillauraLegit", + "Nofall": "NoFall", + "Triggerbot": "TriggerBot", + } + for lang, data in translations.items(): + for key, value in data.items(): + for typo, correct in known_typos.items(): + if typo in value: + issues_found = True + util.add_github_summary( + f"⚠ In {lang}.json string {key}, the word '{correct}' is incorrectly translated as '{typo}':" + ) + util.add_github_summary("```json") + util.add_github_summary(f' "{key}": "{value}"') + util.add_github_summary("```") + + # Difficult strings + for lang, data in translations.items(): + # Boatfly + boatfly_key = "description.wurst.hack.boatfly" + if boatfly_key in data and "shift" in data[boatfly_key].lower(): + issues_found = True + util.add_github_summary( + f"⚠ In {lang}.json, the translation for {boatfly_key} incorrectly suggests using the shift (sneak) key instead of ctrl (sprint) to descend" + ) + # Radar + radar_key = "description.wurst.hack.radar" + if radar_key in data and ( + "§cred§r" in data[radar_key] + # Not checking orange because it appears in the French translation + or "§agreen§r" in data[radar_key] + or "§7gray§r" in data[radar_key] + ): + issues_found = True + util.add_github_summary( + f"⚠ In {lang}.json, the translation for {radar_key} contains untranslated colors:" + ) + util.add_github_summary("```json") + util.add_github_summary(f' "{radar_key}": "{data[radar_key]}"') + util.add_github_summary("```") + + if issues_found: + raise Exception("Found known issues in one or more translation files, see summary") + util.add_github_summary("✅ No known issues found in any translation files") + + def main(): en_us = util.read_json_file(translations_dir / "en_us.json") translations = {} @@ -90,6 +147,7 @@ def main(): check_extra_keys(en_us, translations) check_untranslated_strings(en_us, translations) check_order_of_strings(en_us, translations) + check_known_issues(en_us, translations) if __name__ == "__main__":