mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-06-14 20:11:22 +00:00
Update script
This commit is contained in:
parent
5cb788e8f8
commit
1d2aa58523
@ -7,12 +7,7 @@
|
|||||||
Locales are in folder `./src/i18n/locales`, one folder per language.
|
Locales are in folder `./src/i18n/locales`, one folder per language.
|
||||||
|
|
||||||
A single JSON file represents a namespace (group of translation).
|
A single JSON file represents a namespace (group of translation).
|
||||||
It's a key/value structure.
|
It's a sorted key/value structure.
|
||||||
|
|
||||||
Please:
|
|
||||||
|
|
||||||
- Keep the file sorted
|
|
||||||
- First letter of each value is lowercase
|
|
||||||
|
|
||||||
Translation in GUI:
|
Translation in GUI:
|
||||||
|
|
||||||
|
@ -2,11 +2,13 @@ import os
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from deep_translator import GoogleTranslator
|
from deep_translator import GoogleTranslator
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
# === CONFIGURATION ===
|
# === CONFIGURATION ===
|
||||||
base_folder = "./src/i18n/locales"
|
base_folder = "./src/i18n/locales"
|
||||||
source_lang = "en"
|
source_lang = "en"
|
||||||
filenames = ["auth.json", "core.json", "group.json", "question.json", "tutorial.json"]
|
filenames = ["auth.json", "core.json", "group.json", "question.json", "tutorial.json"]
|
||||||
|
all_target_langs = ["de", "es", "fr", "it", "ja", "ru", "zh"]
|
||||||
|
|
||||||
|
|
||||||
# === SAFE TRANSLATION ===
|
# === SAFE TRANSLATION ===
|
||||||
@ -35,16 +37,8 @@ def translate_json(obj, translator):
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
# === FILE TRANSLATION ===
|
# === WORKER FUNCTION ===
|
||||||
def translate_file(filename, target_lang):
|
def translate_for_language(filename, data, target_lang):
|
||||||
source_path = os.path.join(base_folder, source_lang, filename)
|
|
||||||
if not os.path.isfile(source_path):
|
|
||||||
print(f"❌ File not found: {source_path}")
|
|
||||||
return
|
|
||||||
|
|
||||||
with open(source_path, "r", encoding="utf-8") as f:
|
|
||||||
data = json.load(f)
|
|
||||||
|
|
||||||
print(f"🔁 Translating {filename} → {target_lang}")
|
print(f"🔁 Translating {filename} → {target_lang}")
|
||||||
translator = GoogleTranslator(source=source_lang, target=target_lang)
|
translator = GoogleTranslator(source=source_lang, target=target_lang)
|
||||||
translated = translate_json(data, translator)
|
translated = translate_json(data, translator)
|
||||||
@ -57,6 +51,7 @@ def translate_file(filename, target_lang):
|
|||||||
json.dump(translated, f, ensure_ascii=False, indent=2)
|
json.dump(translated, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
print(f"✅ Saved: {target_path}")
|
print(f"✅ Saved: {target_path}")
|
||||||
|
return target_path
|
||||||
|
|
||||||
|
|
||||||
# === MAIN FUNCTION ===
|
# === MAIN FUNCTION ===
|
||||||
@ -69,12 +64,27 @@ def main():
|
|||||||
print(f"❌ Invalid filename: {filename}")
|
print(f"❌ Invalid filename: {filename}")
|
||||||
return
|
return
|
||||||
|
|
||||||
target_lang = input("Enter the target language code (e.g., de, fr, ja): ").strip()
|
exclude_input = input("Enter languages to exclude (comma-separated, e.g., 'fr,ja'): ").strip()
|
||||||
if not target_lang:
|
excluded_langs = [lang.strip() for lang in exclude_input.split(",") if lang.strip()]
|
||||||
print("❌ No target language provided.")
|
target_langs = [lang for lang in all_target_langs if lang not in excluded_langs]
|
||||||
|
|
||||||
|
if not target_langs:
|
||||||
|
print("❌ All target languages excluded. Nothing to do.")
|
||||||
return
|
return
|
||||||
|
|
||||||
translate_file(filename, target_lang)
|
source_path = os.path.join(base_folder, source_lang, filename)
|
||||||
|
if not os.path.isfile(source_path):
|
||||||
|
print(f"❌ File not found: {source_path}")
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(source_path, "r", encoding="utf-8") as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
# Parallel execution per language
|
||||||
|
with ThreadPoolExecutor(max_workers=len(target_langs)) as executor:
|
||||||
|
futures = [executor.submit(translate_for_language, filename, data, lang) for lang in target_langs]
|
||||||
|
for future in as_completed(futures):
|
||||||
|
_ = future.result()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user