-
-
Notifications
You must be signed in to change notification settings - Fork 672
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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%", | ||
} | ||
] |