From d51e07f1c2a4a0f27cdb9e0a759417c216860e4c Mon Sep 17 00:00:00 2001 From: grdddj Date: Mon, 4 Dec 2023 15:23:46 +0100 Subject: [PATCH] WIP - add crowdin sync script --- .../embed/rust/src/ui/translations/crowdin.py | 55 +++++++++++++++++++ .../rust/src/ui/translations/crowdin.yml | 12 ++++ 2 files changed, 67 insertions(+) create mode 100644 core/embed/rust/src/ui/translations/crowdin.py create mode 100644 core/embed/rust/src/ui/translations/crowdin.yml diff --git a/core/embed/rust/src/ui/translations/crowdin.py b/core/embed/rust/src/ui/translations/crowdin.py new file mode 100644 index 00000000000..1ac121fd158 --- /dev/null +++ b/core/embed/rust/src/ui/translations/crowdin.py @@ -0,0 +1,55 @@ +import subprocess +import tempfile +from pathlib import Path +import json +import sys +import os + +HERE = Path(__file__).parent + + +def download() -> None: + with tempfile.TemporaryDirectory() as temp_dir: + command = f"crowdin download --all --verbose --token $CROWDIN_TOKEN --base-path={temp_dir}" + print("command", command) + + subprocess.run(command, shell=True, check=True) + + for directory in Path(temp_dir).iterdir(): + print("directory", directory) + lang_name = directory.name + en_file = directory / "en.json" + if not en_file.exists(): + print("Skipping - no en.json inside", lang_name) + continue + print("Processing", lang_name) + data = json.loads(en_file.read_text()) + lang_file = HERE / f"{lang_name}.json" + if not lang_file.exists(): + print("Skipping - no lang_file on our side", lang_name) + continue + lang_file_data = json.loads(lang_file.read_text()) + lang_file_data["translations"] = data["translations"] + lang_file.write_text(json.dumps(lang_file_data, indent=2, sort_keys=True, ensure_ascii=False) + "\n") + print("Translations updated", lang_name) + + +def upload() -> None: + command = "crowdin upload sources --token $CROWDIN_TOKEN" + print("command", command) + + subprocess.run(command, shell=True, check=True) + + +if __name__ == "__main__": + if not os.environ.get("CROWDIN_TOKEN"): + print("CROWDIN_TOKEN env variable not set") + sys.exit(1) + + if "download" in sys.argv: + download() + elif "upload" in sys.argv: + upload() + else: + print("Usage: python crowdin.py [download|upload]") + sys.exit(1) diff --git a/core/embed/rust/src/ui/translations/crowdin.yml b/core/embed/rust/src/ui/translations/crowdin.yml new file mode 100644 index 00000000000..410bae43abc --- /dev/null +++ b/core/embed/rust/src/ui/translations/crowdin.yml @@ -0,0 +1,12 @@ +"project_id" : "625982" +"base_path" : "." +# api_token is being supplied on via `--token $CROWDIN_TOKEN` CLI option +"base_url" : "https://api.crowdin.com" +"preserve_hierarchy": true + +files: [ + { + "source" : "en.json", + "translation": "%two_letters_code%/%original_file_name%", + } +]