mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
b8ea21d24a
Co-authored-by matejcik <ja@matejcik.cz>
56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
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)
|