Skip to content

Commit

Permalink
WIP - add crowdin sync script
Browse files Browse the repository at this point in the history
  • Loading branch information
grdddj committed Dec 4, 2023
1 parent c0ddc57 commit d51e07f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
55 changes: 55 additions & 0 deletions core/embed/rust/src/ui/translations/crowdin.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 12 additions & 0 deletions core/embed/rust/src/ui/translations/crowdin.yml
Original file line number Diff line number Diff line change
@@ -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%",
}
]

0 comments on commit d51e07f

Please sign in to comment.