feat: 更新 Crowdin 工作流以支持 dashboard WebUI 的本地化文件,添加相关验证逻辑

This commit is contained in:
春河晴
2026-03-13 20:09:21 +09:00
parent 5f5ff4ce8e
commit 5da82c4e24
8 changed files with 283 additions and 15 deletions

View File

@@ -19,6 +19,11 @@ def write_locale_file(locales_root: Path, locale: str, file_name: str, payload:
(locale_dir / file_name).write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
def write_dashboard_locale_file(locales_root: Path, locale: str, payload: dict[str, object]) -> None:
locales_root.mkdir(parents=True, exist_ok=True)
(locales_root / f"{locale}.json").write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
def test_validate_json_locales_rejects_han_characters_in_english_locale(tmp_path: Path) -> None:
locales_root = tmp_path / "locales"
write_locale_file(locales_root, "zh-CN", "core.json", {"consent.prompt": '输入"同意"继续'})
@@ -68,3 +73,38 @@ def test_validate_json_locales_avoids_false_positive_when_plural_categories_do_n
assert any("tasks.cancelled" in error and "plural category 不一致" in error for error in errors)
assert not any("tasks.cancelled" in error and "直接保留了包含中文字符的 source 文案" in error for error in errors)
def test_validate_dashboard_json_locales_rejects_han_characters_in_english_locale(tmp_path: Path) -> None:
locales_root = tmp_path / "dashboard-locales"
write_dashboard_locale_file(locales_root, "zh", {"common": {"greeting": "你好,世界"}})
write_dashboard_locale_file(locales_root, "en", {"common": {"greeting": "Hello 同意"}})
errors = I18N_VALIDATE.validate_dashboard_json_locales(locales_root)
assert any("dashboard:en" in error and "common.greeting" in error and "仍包含中文字符" in error for error in errors)
def test_validate_dashboard_json_locales_rejects_untranslated_han_source_in_other_target_locales(
tmp_path: Path,
) -> None:
locales_root = tmp_path / "dashboard-locales"
write_dashboard_locale_file(locales_root, "zh", {"common": {"greeting": "你好,世界"}})
write_dashboard_locale_file(locales_root, "ja", {"common": {"greeting": "你好,世界"}})
errors = I18N_VALIDATE.validate_dashboard_json_locales(locales_root)
assert any(
"dashboard:ja" in error and "common.greeting" in error and "直接保留了包含中文字符的 source 文案" in error
for error in errors
)
def test_validate_dashboard_json_locales_rejects_i18next_placeholder_drift(tmp_path: Path) -> None:
locales_root = tmp_path / "dashboard-locales"
write_dashboard_locale_file(locales_root, "zh", {"status": {"checkingDesc": "等待服务恢复... ({{current}}/{{max}})"}})
write_dashboard_locale_file(locales_root, "ko", {"status": {"checkingDesc": "서비스 복구 대기 중... ({{current}}/{{limit}})"}})
errors = I18N_VALIDATE.validate_dashboard_json_locales(locales_root)
assert any("dashboard:ko" in error and "status.checkingDesc" in error and "占位符集合与 source 不一致" in error for error in errors)