The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
refactor(i18n): Crowdin v3 + Android XML 纳入 Crowdin 管线
XiaoYouChR50ac55aeb854
diff --git a/.github/workflows/crowdin.yml b/.github/workflows/crowdin.ymlindex d0f61fe7..43d76a90 100644--- a/.github/workflows/crowdin.yml+++ b/.github/workflows/crowdin.yml@@ -56,7 +56,7 @@ jobs:- name: Upload sources and translationsif: github.event.inputs.operation == 'push'- uses: crowdin/github-action@v2+ uses: crowdin/github-action@v3with:config: crowdin.ymlupload_sources: true@@ -66,7 +66,7 @@ jobs:- name: Download translationsif: github.event.inputs.operation == 'pull'- uses: crowdin/github-action@v2+ uses: crowdin/github-action@v3with:config: crowdin.ymldownload_translations: true@@ -79,7 +79,7 @@ jobs:- name: Prepare downloaded translationsif: github.event.inputs.operation == 'pull'run: |- sudo chown -R "$(id -u):$(id -g)" .git app/assets+ sudo chown -R "$(id -u):$(id -g)" .git app/assets compose/app/src/main/resrm -f .git/COMMIT_EDITMSGpython scripts/sync_i18n_res.py@@ -114,10 +114,12 @@ jobs:This PR was created automatically by the Crowdin sync workflow.It refreshes the Qt `.ts` files, compiled `.qm` files,- `app/assets/resources.py`, and Crowdin contributors in both READMEs.+ `app/assets/resources.py`, Android string resources,+ and Crowdin contributors in both READMEs.add-paths: |app/assets/i18n/*.tsapp/assets/i18n/*.qmapp/assets/resources.py+ compose/app/src/main/res/README.mdREADME_zh.mddiff --git a/crowdin.yml b/crowdin.ymlindex 24c3391d..b2db4401 100644--- a/crowdin.yml+++ b/crowdin.yml@@ -15,3 +15,18 @@ files:zh-HK: zh_HKpt-BR: pt_BRes-ES: es_ES++ - source: /compose/app/src/main/res/values/strings*.xml+ translation: /compose/app/src/main/res/values-%android_code%/%original_file_name%+ type: android+ ignore:+ - /compose/app/src/main/res/values/strings_engine.xml+ languages_mapping:+ android_code:+ en-US: en+ ja: ja+ ru: ru+ zh-TW: zh-rTW+ zh-HK: zh-rHK+ pt-BR: pt-rBR+ es-ES: esdiff --git a/scripts/sync_i18n_res.py b/scripts/sync_i18n_res.pyindex 5bcda918..5087e19a 100644--- a/scripts/sync_i18n_res.py+++ b/scripts/sync_i18n_res.py@@ -129,6 +129,14 @@ def readCatalog(locale: str) -> dict[str, tuple[str, str]]:return entries++def escapeAndroidString(text: str) -> str:+ for old, new in (("&", "&"), ("<", "<"), (">", ">"),+ ("'", "\\'"), ('"', '\\"')):+ text = text.replace(old, new)+ return text++def buildAndroidStrings() -> None:source = readCatalog("zh_CN")if not source:@@ -148,10 +156,7 @@ def buildAndroidStrings() -> None:target.mkdir(parents=True, exist_ok=True)xmlLines = ["<!-- Generated by scripts/sync_i18n_res.py -->", "<resources>"]for resource in sorted(entries):- text = entries[resource][1]- for old, new in (("&", "&"), ("<", "<"), (">", ">"),- ("'", "\\'"), ('"', '\\"')):- text = text.replace(old, new)+ text = escapeAndroidString(entries[resource][1])xmlLines.append(f' <string name="{resource}" formatted="false">{text}</string>')@@ -174,6 +179,7 @@ def buildAndroidStrings() -> None:COMPOSE_I18N_KT.write_text("\n".join(ktLines) + "\n", encoding="utf-8")+def buildResources() -> None:rcc = findTool("pyside6-rcc")subprocess.run([diff --git a/scripts/translate_i18n.py b/scripts/translate_i18n.pyindex 736c842b..5e48e3ae 100644--- a/scripts/translate_i18n.py+++ b/scripts/translate_i18n.py@@ -11,6 +11,26 @@ REPO = Path(__file__).resolve().parent.parentI18N_DIR = REPO / "app" / "assets" / "i18n"BROWSER_I18N_DIR = REPO / "browser_extension" / "app" / "public" / "_locales"+COMPOSE_RES_DIR = REPO / "compose" / "app" / "src" / "main" / "res"+ANDROID_SOURCE_FILES = [+ "strings.xml",+ "strings_identity.xml",+ "strings_settings.xml",+ "strings_settings_edit.xml",+ "strings_settings_flow.xml",+ "strings_task_bar.xml",+ "strings_tasks.xml",+]+ANDROID_LOCALE_FOLDERS = {+ "en_US": "values-en",+ "ja_JP": "values-ja",+ "ru_RU": "values-ru",+ "zh_TW": "values-zh-rTW",+ "zh_HK": "values-zh-rHK",+ "pt_BR": "values-pt-rBR",+ "es_ES": "values-es",+}+API_KEY = os.environ.get("DEEPSEEK_API_KEY", "")API_URL = "https://api.deepseek.com/chat/completions"MODEL = "deepseek-v4-pro"@@ -22,6 +42,7 @@ LOCALES = {"zh_HK": "繁體中文 (Hong Kong)","zh_TW": "繁體中文 (Taiwan)","pt_BR": "Português (Brasil)",+ "es_ES": "Español (España)",}SYSTEM_PROMPT_DESKTOP = """\@@ -49,6 +70,17 @@ SYSTEM_PROMPT_BROWSER = """\4. 只输出待翻译部分的结果5. 不要输出解释、注释、markdown 标记"""+SYSTEM_PROMPT_ANDROID = """\+你是专业软件本地化译员。将下载管理器 "Ghost Downloader 3" 的 Android 端 UI 文本从简体中文译为 {locale_name}。++规则:+1. Android 格式化占位符 %1$s %2$d %d%% 等必须原样保留,位置和数量不变+2. \\n 表示换行,保留在译文相同位置+3. 参考「已有翻译」的术语和语气+4. 严格保持 "name = 译文" 格式输出,每行一条+5. 只输出待翻译部分的结果+6. 不要输出解释、注释、markdown 标记"""+def escapeNewlines(s: str) -> str:return s.replace("\\", "\\\\").replace("\n", "\\n")@@ -333,10 +365,160 @@ def checkBrowserLocales(locales: dict[str, str]) -> int:return total+def parseAndroidStrings(path: Path) -> dict[str, str]:+ if not path.exists():+ return {}+ root = ET.parse(path).getroot()+ entries = {}+ for elem in root.findall("string"):+ if elem.get("translatable") == "false":+ continue+ name = elem.get("name")+ text = elem.text or ""+ if name and text:+ entries[name] = text+ return entries+++def buildAndroidPrompt(+ existing: dict[str, tuple[str, str]],+ untranslated: dict[str, tuple[str, str]],+) -> str:+ lines = []+ if existing:+ lines.append("## 已有翻译")+ currentFile = None+ for name, (fname, text) in existing.items():+ if fname != currentFile:+ lines.append(f"=== {fname} ===")+ currentFile = fname+ lines.append(f"{name} = {escapeNewlines(text)}")+ lines.append("")++ lines.append("## 待翻译")+ currentFile = None+ for name, (fname, text) in untranslated.items():+ if fname != currentFile:+ lines.append(f"=== {fname} ===")+ currentFile = fname+ lines.append(f"{name} = {escapeNewlines(text)}")++ return "\n".join(lines)+++def parseAndroidResponse(text: str) -> dict[str, str]:+ translations = {}+ for raw in text.split("\n"):+ line = raw.strip()+ if not line or line.startswith("#") or line.startswith("==="):+ continue+ if " = " in line:+ name, trans = line.split(" = ", 1)+ trans = trans.strip()+ if trans:+ translations[name.strip()] = unescapeNewlines(trans)+ return translations+++def escapeAndroidXml(text: str) -> str:+ for old, new in (("&", "&"), ("<", "<"), (">", ">"),+ ("'", "\\'"), ('"', '\\"')):+ text = text.replace(old, new)+ return text+++def translateAndroidLocale(locale: str, localeName: str) -> None:+ folder = ANDROID_LOCALE_FOLDERS.get(locale)+ if not folder:+ print(f"[android:{locale}] No folder mapping")+ return++ sourceDir = COMPOSE_RES_DIR / "values"+ localeDir = COMPOSE_RES_DIR / folder++ allSource: dict[str, tuple[str, str]] = {}+ allExisting: dict[str, tuple[str, str]] = {}+ untranslated: dict[str, tuple[str, str]] = {}++ for fname in ANDROID_SOURCE_FILES:+ source = parseAndroidStrings(sourceDir / fname)+ existing = parseAndroidStrings(localeDir / fname)+ for name, text in source.items():+ allSource[name] = (fname, text)+ if name in existing:+ allExisting[name] = (fname, existing[name])+ else:+ untranslated[name] = (fname, text)++ if not untranslated:+ print(f"[android:{locale}] Nothing to translate")+ return++ print(f"[android:{locale}] {len(untranslated)} untranslated, {len(allExisting)} reference …")++ system = SYSTEM_PROMPT_ANDROID.format(locale_name=localeName)+ user = buildAndroidPrompt(allExisting, untranslated)+ print(f"[android:{locale}] Calling API ({len(user)} chars) …")++ response = fetchTranslation(system, user)+ translations = parseAndroidResponse(response)++ fileEntries: dict[str, dict[str, str]] = {}+ filled = 0+ for name, trans in translations.items():+ if name in allSource:+ fname = allSource[name][0]+ fileEntries.setdefault(fname, {})+ fileEntries[fname][name] = trans+ filled += 1++ localeDir.mkdir(parents=True, exist_ok=True)+ for fname in ANDROID_SOURCE_FILES:+ source = parseAndroidStrings(sourceDir / fname)+ existing = parseAndroidStrings(localeDir / fname)+ newTranslations = fileEntries.get(fname, {})+ merged = {**existing, **newTranslations}+ final = {k: v for k, v in merged.items() if k in source}+ if not final:+ continue+ xmlLines = ["<?xml version=\"1.0\" encoding=\"utf-8\"?>", "<resources>"]+ for name in sorted(final):+ text = escapeAndroidXml(final[name])+ xmlLines.append(f' <string name="{name}">{text}</string>')+ xmlLines.append("</resources>")+ (localeDir / fname).write_text("\n".join(xmlLines) + "\n", encoding="utf-8")++ missed = len(untranslated) - filled+ status = "done" if missed == 0 else f"done ({missed} missed)"+ print(f"[android:{locale}] {status}: {filled}/{len(untranslated)} filled")+++def checkAndroidLocales(locales: dict[str, str]) -> int:+ total = 0+ sourceDir = COMPOSE_RES_DIR / "values"+ for locale in locales:+ folder = ANDROID_LOCALE_FOLDERS.get(locale)+ if not folder:+ continue+ localeDir = COMPOSE_RES_DIR / folder+ missing = 0+ for fname in ANDROID_SOURCE_FILES:+ source = parseAndroidStrings(sourceDir / fname)+ existing = parseAndroidStrings(localeDir / fname)+ missing += len(set(source) - set(existing))+ total += missing+ if missing > 0:+ print(f" android:{locale}: {missing} untranslated")+ else:+ print(f" android:{locale}: up to date")+ return total++def main() -> int:args = sys.argv[1:]check = "--check" in argsbrowser = "--browser" in args+ android = "--android" in argstargets = [a for a in args if not a.startswith("-")]if targets:@@ -350,14 +532,24 @@ def main() -> int:locales = LOCALESif check:- total = checkBrowserLocales(locales) if browser else checkLocales(locales)+ if android:+ total = checkAndroidLocales(locales)+ elif browser:+ total = checkBrowserLocales(locales)+ else:+ total = checkLocales(locales)return 0 if total == 0 else 2if not API_KEY:print("Set DEEPSEEK_API_KEY environment variable", file=sys.stderr)return 1- translateFn = translateBrowserLocale if browser else translateLocale+ if android:+ translateFn = translateAndroidLocale+ elif browser:+ translateFn = translateBrowserLocale+ else:+ translateFn = translateLocalefailed = Falsewith ThreadPoolExecutor(max_workers=len(locales)) as pool: