Skip to content

Commit

Permalink
feat: Add new setup to auto translate locales.
Browse files Browse the repository at this point in the history
Signed-off-by: loonghao <[email protected]>
  • Loading branch information
loonghao committed May 20, 2024
1 parent 4ed86ac commit 03c2303
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
36 changes: 18 additions & 18 deletions maya_umbrella/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"start_fix_issues": "Start fixing all problems related to Maya virus $name",
"finish_fix_issues": "Done.",
"init_message": "Successfully loaded <hl>maya_umbrella</hl> under protection.",
"init_standalone_message": "-----------------------Loading maya_umbrella successfully----------------------",
"report_issue": "$name: Infected by Malware!",
"infected_nodes": "Infected nodes: $name: ",
"bad_files": "Bad files: $name",
"infected_script_jobs": "Infected script jobs: $name",
"infected_files": "Infected files: $name",
"infected_reference_files": "Infected reference files: $name",
"fix_infected_files": "Clean infected files: $name",
"fix_infected_nodes": "Delete infected nodes:$name",
"fix_infected_reference_nodes": "trying fix infected nodes from reference$name",
"delete": "Deleting: $name",
"remove_file": "Deleting file$name",
"remove_path": "Deleting path:$name",
"fix_script_job": "Kill script job: %s",
"file_not_writable": "File not writable: $name"
"start_fix_issues": "Start fixing all problems related to Maya virus $name",
"finish_fix_issues": "Repair completed.",
"init_message": "Successfully loaded <hl>maya_umbrella</hl> protection.",
"init_standalone_message": "----------------------- successfully loaded maya_umbrella-----------------------",
"report_issue": "$name: Maliciously infected!",
"infected_nodes": "Infected node: $name:",
"bad_files": "Files to be cleaned up: $name",
"infected_script_jobs": "Infected Script jobs: $name",
"infected_files": "Infected file: $name",
"infected_reference_files": "Infected reference file: $name",
"fix_infected_files": "Clean up infected files: $name",
"fix_infected_nodes": "Delete infected node: $name",
"fix_infected_reference_nodes": "Attempt to repair the infected reference node: $name",
"delete": "Delete infected files: $name",
"remove_file": "Delete file: $name",
"remove_path": "Delete folder: $name",
"fix_script_job": "Delete infected node: $name",
"file_not_writable": "The file is not writable: $name"
}
4 changes: 2 additions & 2 deletions maya_umbrella/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"report_issue": "$name:被恶意感染!",
"infected_nodes": "被感染节点:$name: ",
"bad_files": "需要被清理的文件:$name",
"infected_script_jobs": "被感染的script jobs:$name",
"infected_files": "被感染的脚本:$name",
"infected_script_jobs": "被感染的Script jobs:$name",
"infected_files": "被感染的文件:$name",
"infected_reference_files": "被感染的参考文件:$name",
"fix_infected_files": "清理被感染的文件:$name",
"fix_infected_nodes": "删除被感染的节点:$name",
Expand Down
5 changes: 5 additions & 0 deletions nox_actions/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,8 @@ def pinned_requirements(path: Path) -> Iterator[Tuple[str, str]]:

# synchronize the contents
session.run("vendoring", "sync", ".")


def translate(session: nox.Session) -> None:
session.install("deepl", "maya-umbrella")
session.run("python", os.path.join(THIS_ROOT, "scripts", "translate_i18n.py"), THIS_ROOT)
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
nox.session(release.make_install_zip, name="make-zip")
nox.session(codetest.pytest, name="pytest")
nox.session(release.vendoring, name="vendoring")
nox.session(release.translate, name="t")
29 changes: 29 additions & 0 deletions scripts/translate_i18n.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Import built-in modules
import json
import os
import sys

# Import third-party modules
import deepl

# Import local modules
from maya_umbrella.filesystem import read_json


def translate_locales(this_root):
auth_key = os.getenv("DEEPL_API_KEY") # Replace with your key
translator = deepl.Translator(auth_key)
locales_root = os.path.join(this_root, "maya_umbrella", "locales")
zh_cn = os.path.join(locales_root, "zh_CN.json")
dest_data = {}
src_data = read_json(zh_cn)
for key, value in src_data.items():
result = translator.translate_text(value, target_lang="EN-US")
print(result.text)
dest_data[key] = result.text
with open(os.path.join(locales_root, "en_US.json"), "w") as f:
json.dump(dest_data, f, indent=4)


if __name__ == "__main__":
translate_locales(sys.argv[-1])

0 comments on commit 03c2303

Please sign in to comment.