使用'模型翻译'进行阿拉伯语 - 英语翻译。一旦我登录并更改为阿拉伯语,然后注销语言更改为英语。
这是我的退出代码:,我在注销后激活了语言,它将语言打印为'ar'但显示英语。请帮助我
def profile_logout(request,mode=None, **kwars):
lang = request.LANGUAGE_CODE
response = logout(request, **kwars)
translation.activate(lang)
print "langggggggggggggggggggggggggggggggggg",request.LANGUAGE_CODE
return response
答案 0 :(得分:3)
我通过创建会话对我的观点进行了一些更改。希望有人能够使用这个。这对我有用。
def profile_logout(request,mode=None, **kwars):
lang = request.LANGUAGE_CODE
translation.activate(lang)
language=request.session.get('django_language')
print "languageeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",language
response = logout(request, **kwars)
if language is not None:
request.session['django_language'] = language
print
"request.session['django_language']request.session['django_language']request.session['django_language']",request.session['django_language']
return response
或参考:
``https://github.com/ludwiktrammer/django/commit/adfb2c114f94df4a77a9424001e300f0552c6e20
答案 1 :(得分:0)
您应该在处理模板之前激活翻译,例如在致电logout
之前。类似的东西:
def profile_logout(request,mode=None, **kwars):
lang = request.LANGUAGE_CODE
translation.activate(lang)
response = logout(request, **kwars)
print "langggggggggggggggggggggggggggggggggg",request.LANGUAGE_CODE
return response