fix: 修复语言切换问题

pull/9960/head
Bai 2023-03-14 14:32:31 +08:00 committed by Jiangjie.Bai
parent b76aa3b259
commit 32cba4f2a1
1 changed files with 10 additions and 4 deletions

View File

@ -519,8 +519,14 @@ class AuthMixin(CommonMixin, AuthPreCheckMixin, AuthACLMixin, MFAMixin, AuthPost
def set_browser_default_language_if_need(self, response):
# en, ja, zh-CN,zh;q=0.9
default_lang = self.request.headers.get('Accept-Language')
if 'zh' in default_lang:
default_lang = 'zh'
lang = response.cookies.get(settings.LANGUAGE_COOKIE_NAME) or default_lang
browser_lang = self.request.headers.get('Accept-Language', '')
# 浏览器首选语言
if browser_lang.startswith('en'):
browser_lang = 'en'
elif browser_lang.startswith('ja'):
browser_lang = 'ja'
else:
browser_lang = 'zh'
request_lang = self.request.LANGUAGE_CODE
lang = request_lang or browser_lang
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang)