Python django.views.i18n.set_language() Examples

The following are 11 code examples of django.views.i18n.set_language(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.views.i18n , or try the search function .
Example #1
Source File: views.py    From Kiwi with GNU General Public License v2.0 7 votes vote down vote up
def get(self, request):
        """
            In the HTML template we'd like to work with simple links
            however the view which actually switches the language needs
            to be called via POST so we simulate that here!

            If the URL doesn't explicitly specify language then we turn-off
            translation mode by switching back to browser preferred language.
        """
        browser_lang = self.get_browser_language(request)
        post_body = "%s=%s" % (i18n.LANGUAGE_QUERY_PARAMETER,
                               request.GET.get(i18n.LANGUAGE_QUERY_PARAMETER, browser_lang))
        request.META['REQUEST_METHOD'] = 'POST'
        request.META['CONTENT_LENGTH'] = len(post_body)
        request.META['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'

        post_request = request.__class__(request.META)
        # pylint: disable=protected-access
        post_request._post = http.QueryDict(post_body, encoding=post_request._encoding)

        return i18n.set_language(post_request) 
Example #2
Source File: language.py    From StormOnline with Apache License 2.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #3
Source File: language.py    From weibo-analysis-system with MIT License 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #4
Source File: language.py    From myblog with GNU Affero General Public License v3.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #5
Source File: language.py    From CTF_AWD_Platform with MIT License 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #6
Source File: language.py    From django_OA with GNU General Public License v3.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #7
Source File: language.py    From Mxonline3 with Apache License 2.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #8
Source File: language.py    From imoocc with GNU General Public License v2.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #9
Source File: language.py    From online with GNU Affero General Public License v3.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #10
Source File: language.py    From Dailyfresh-B2C with Apache License 2.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request) 
Example #11
Source File: language.py    From ImitationTmall_Django with GNU General Public License v3.0 5 votes vote down vote up
def post(self, request, *args, **kwargs):
        if 'nav_menu' in request.session:
            del request.session['nav_menu']
        return set_language(request)