Skip to content

A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物

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

ghostubbornf2404903d6e1
diff --git a/backend/app/utils/locale.py b/backend/app/utils/locale.py
index 868c4f0b..23d04aa9 100644
--- a/backend/app/utils/locale.py
+++ b/backend/app/utils/locale.py
@@ -27,7 +27,8 @@ def set_locale(locale: str):
def get_locale() -> str:
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')