0

我正在使用“模型翻译”进行阿拉伯语-英语翻译。一旦我登录并更改为阿拉伯语,然后注销语言更改为英语。

这是我的注销代码:,我在注销后激活了语言,它将语言打印为“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
4

2 回答 2

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

于 2014-01-20T12:41:46.587 回答
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
于 2014-01-20T11:52:06.550 回答