mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 00:29:37 +08:00
* fix(i18n): accept Korean as a backend interface language The web picker offers Korean (added in #2359), but the backend UiLanguage contract, its normalizers and the settings spec never learned "ko". Choosing Korean and applying settings therefore fails with HTTP 422 on PUT /api/settings/ui, and the saved language falls back to English on the next load. Register "ko" in the same seams Japanese used in #2213: UiLanguage and _normalize_language() in interface_settings.py, the launch-settings normalizer, and _LANGUAGE_CHOICES in settings_spec.py, then regenerate the frontend API contracts. Add Korean to the existing router and launch-settings tests, and add a registry test that fails whenever a web APP_LANGUAGES code is missing from the backend contract. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: apply ruff format Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.1 KiB
Python
59 lines
2.1 KiB
Python
"""Every web interface locale must also exist on the backend.
|
|
|
|
The web picker (``APP_LANGUAGES`` in ``web/i18n/languages.ts``) and the
|
|
backend ``UiLanguage`` contract are maintained separately. When a locale is
|
|
added to the picker only, ``PUT /api/settings/ui`` rejects it with 422 and the
|
|
saved language snaps back to English on the next load, so the picker offers a
|
|
language the app cannot keep. These tests pin the two lists together.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import re
|
|
from typing import get_args
|
|
|
|
import pytest
|
|
|
|
from deeptutor.services.config.launch_settings import _normalize_language as _launch_language
|
|
from deeptutor.services.config.settings_spec import _LANGUAGE_CHOICES
|
|
from deeptutor.services.settings.interface_settings import UiLanguage, _normalize_language
|
|
|
|
LANGUAGES_TS = Path(__file__).resolve().parents[2] / "web" / "i18n" / "languages.ts"
|
|
|
|
|
|
def _web_interface_languages() -> list[str]:
|
|
source = LANGUAGES_TS.read_text(encoding="utf-8")
|
|
block = re.search(r"APP_LANGUAGES\s*=\s*\[(.*?)\]\s*as const", source, re.S)
|
|
assert block, "APP_LANGUAGES not found in web/i18n/languages.ts"
|
|
codes = re.findall(r'code:\s*"([^"]+)"', block.group(1))
|
|
assert codes, "APP_LANGUAGES has no codes"
|
|
return codes
|
|
|
|
|
|
WEB_LANGUAGES = _web_interface_languages()
|
|
|
|
|
|
@pytest.mark.parametrize("code", WEB_LANGUAGES)
|
|
def test_web_interface_language_is_a_backend_ui_language(code: str) -> None:
|
|
assert code in get_args(UiLanguage)
|
|
|
|
|
|
@pytest.mark.parametrize("code", WEB_LANGUAGES)
|
|
def test_web_interface_language_survives_backend_normalization(code: str) -> None:
|
|
assert _normalize_language(code) == code
|
|
assert _launch_language(code) == code
|
|
|
|
|
|
@pytest.mark.parametrize("code", WEB_LANGUAGES)
|
|
def test_web_interface_language_is_offered_in_settings_spec(code: str) -> None:
|
|
assert code in {choice_code for choice_code, _label, _description in _LANGUAGE_CHOICES}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"raw", ["ko", "KO", " ko ", "ko-KR", "ko_KR", "korean", "Korean", "한국어"]
|
|
)
|
|
def test_korean_aliases_normalize_to_ko(raw: str) -> None:
|
|
assert _normalize_language(raw) == "ko"
|
|
assert _launch_language(raw) == "ko"
|