fix(i18n): validate Accept-Language header against registered locales
This commit is contained in:
parent
2421010fe1
commit
f2404903d6
|
|
@ -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')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue