fix(i18n): validate Accept-Language header against registered locales

This commit is contained in:
ghostubborn 2026-04-02 14:01:24 +08:00
parent 2421010fe1
commit f2404903d6
1 changed files with 2 additions and 1 deletions

View File

@ -27,7 +27,8 @@ def set_locale(locale: str):
def get_locale() -> str: def get_locale() -> str:
if has_request_context(): if has_request_context():
return request.headers.get('Accept-Language', 'zh') raw = request.headers.get('Accept-Language', 'zh')
return raw if raw in _translations else 'zh'
return getattr(_thread_local, 'locale', 'zh') return getattr(_thread_local, 'locale', 'zh')