mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-05 20:09:40 +08:00
Complete full-stack activation of Traditional Chinese (zh-tw) on top of #3064 and #3065: - Review and refine 683 app.json entries and 9 common.json entries in web/locales/zh-tw/ for Taiwan Traditional Chinese terminology (fixing OpenCC s2twp artifacts and mainland variants such as 許可權→權限, 賬號/賬戶→帳號/帳戶, 回撥→回呼, 自定義→自訂, 閘道器→閘道, 例項→實例, 只讀→唯讀, 憑據→憑證, 服務端→伺服器端, 配置檔案→設定檔, 地址→位址, 埠→連接埠, 映象→映像/鏡像, and curly quotes→「」) while keeping every key, placeholder, code span, and URL intact. - Add language.chinese_traditional ("繁體中文") across all 14 web locale catalogs (and portuguese_unchanged_ui.json). - Register zh-tw in web/i18n/languages.ts (preserving zh-tw/zh-hk/zh-mo/zh-hant before zh), dynamic loader web/i18n/init.ts, and web/lib/datetime.ts (zh-TW). - Add complete Traditional Chinese Desktop shell copy in apps/desktop/src/i18n.mjs and register zh-tw in apps/desktop/src/main.mjs with zh-tw/zh-hant normalization. - Wire zh-tw into backend deterministic copy and settings: settings_spec.py, runtime/banner.py, services/i18n.py, book/overview_copy.py, book/export.py, book/language.py, api/routers/quiz_judge.py (+ router_index.json), and zh-hk/zh-mo/zh-hant/繁體中文 handling in interface_languages.py and interface_settings.py (_normalize_response_language). - Add full-stack regression coverage in tests/i18n/test_traditional_chinese_locale.py, apps/desktop/test/i18n.test.mjs, web/tests/language-preferences.test.ts, web/tests/account-role.test.ts, and tests/book/test_overview_copy.py. Related to #2933 Related to #684
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
"""One backend locale contract for settings and process startup."""
|
|
|
|
from typing import get_args
|
|
|
|
import pytest
|
|
|
|
from deeptutor.core.interface_languages import (
|
|
SUPPORTED_UI_LANGUAGES,
|
|
UiLanguage,
|
|
normalize_ui_language,
|
|
)
|
|
from deeptutor.services.config.launch_settings import _normalize_language as launch_language
|
|
from deeptutor.services.settings.interface_settings import _normalize_language, resolve_languages
|
|
|
|
|
|
@pytest.mark.parametrize("code", SUPPORTED_UI_LANGUAGES)
|
|
def test_registry_and_both_backend_normalizers_agree(code):
|
|
assert code in get_args(UiLanguage)
|
|
assert normalize_ui_language(code) == _normalize_language(code) == launch_language(code) == code
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"raw,expected",
|
|
[
|
|
(" ZH_TW ", "zh-tw"),
|
|
("zh-Hant", "zh-tw"),
|
|
("zh-Hant-TW", "zh-tw"),
|
|
("zh-HK", "zh-tw"),
|
|
("traditional chinese", "zh-tw"),
|
|
("繁體中文", "zh-tw"),
|
|
("zh-CN", "zh"),
|
|
("zh-Hans", "zh"),
|
|
("ko-KR", "ko"),
|
|
("korean", "ko"),
|
|
("한국어", "ko"),
|
|
("français", "fr"),
|
|
("deutsch", "de"),
|
|
("ua", "uk"),
|
|
("jp", "ja"),
|
|
],
|
|
)
|
|
def test_region_and_name_aliases_survive_startup(raw, expected):
|
|
assert (
|
|
normalize_ui_language(raw) == _normalize_language(raw) == launch_language(raw) == expected
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("raw", [None, 12, "", "xx", "unsupported"])
|
|
def test_callers_keep_distinct_fallback_policies(raw):
|
|
assert launch_language(raw) is None
|
|
assert _normalize_language(raw, "fr") == "fr"
|
|
assert _normalize_language(raw, "unsupported") == "en"
|
|
|
|
|
|
@pytest.mark.parametrize("code", SUPPORTED_UI_LANGUAGES)
|
|
def test_legacy_migration_and_explicit_reply_preference_remain_separate(code):
|
|
assert resolve_languages({"language": code}) == {"language": code, "response_language": code}
|
|
assert resolve_languages({"language": code, "response_language": "ja"}) == {
|
|
"language": code,
|
|
"response_language": "ja",
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize("code", ["es", "es-ES", "Spanish"])
|
|
def test_unshipped_interface_languages_are_not_activated(code):
|
|
assert normalize_ui_language(code) is None
|
|
assert launch_language(code) is None
|
|
assert _normalize_language(code) == "en"
|
|
|
|
|
|
@pytest.mark.parametrize("code", ["es"])
|
|
def test_output_only_languages_remain_valid_reply_preferences(code):
|
|
assert code not in SUPPORTED_UI_LANGUAGES
|
|
assert resolve_languages({"language": "ko", "response_language": code}) == {
|
|
"language": "ko",
|
|
"response_language": code,
|
|
}
|