src/cm/views/i18n.py
author gibus
Mon, 14 Nov 2011 10:16:54 +0100
changeset 391 284692d9d504
parent 0 40c8f766c9b8
permissions -rw-r--r--
add_comment_button should be hidden with initially_hidden css class if can_create_comment permission is false => do not set this css property directly on html element.

from django import http
from django.utils.translation import check_for_language, activate, to_locale, get_language
from django.utils.text import javascript_quote
from django.conf import settings
import os
import gettext as gettext_module

# taken from django/views/i18n.py
# to allow GET change (flickr does it)
def set_language(request, lang_code):
    """
    Redirect to a given url while setting the chosen language in the
    session or cookie. The url and the language code need to be
    specified in the request parameters.

    Since this view changes how the user will see the rest of the site, it must
    only be accessed as a POST request. If called as a GET request, it will
    redirect to the page in the request (the 'next' parameter) without changing
    any state.
    """
    next = request.REQUEST.get('next', None)
    if not next:
        next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = '/'
    response = http.HttpResponseRedirect(next)
    if request.method == 'GET':
        #lang_code = request.GET.get('language', None)
        if lang_code and check_for_language(lang_code):
            if hasattr(request, 'session'):
                request.session['django_language'] = lang_code
            else:
                response.set_cookie('django_language', lang_code)
    return response