src/cm/views/i18n.py
changeset 0 40c8f766c9b8
equal deleted inserted replaced
-1:000000000000 0:40c8f766c9b8
       
     1 from django import http
       
     2 from django.utils.translation import check_for_language, activate, to_locale, get_language
       
     3 from django.utils.text import javascript_quote
       
     4 from django.conf import settings
       
     5 import os
       
     6 import gettext as gettext_module
       
     7 
       
     8 # taken from django/views/i18n.py
       
     9 # to allow GET change (flickr does it)
       
    10 def set_language(request, lang_code):
       
    11     """
       
    12     Redirect to a given url while setting the chosen language in the
       
    13     session or cookie. The url and the language code need to be
       
    14     specified in the request parameters.
       
    15 
       
    16     Since this view changes how the user will see the rest of the site, it must
       
    17     only be accessed as a POST request. If called as a GET request, it will
       
    18     redirect to the page in the request (the 'next' parameter) without changing
       
    19     any state.
       
    20     """
       
    21     next = request.REQUEST.get('next', None)
       
    22     if not next:
       
    23         next = request.META.get('HTTP_REFERER', None)
       
    24     if not next:
       
    25         next = '/'
       
    26     response = http.HttpResponseRedirect(next)
       
    27     if request.method == 'GET':
       
    28         #lang_code = request.GET.get('language', None)
       
    29         if lang_code and check_for_language(lang_code):
       
    30             if hasattr(request, 'session'):
       
    31                 request.session['django_language'] = lang_code
       
    32             else:
       
    33                 response.set_cookie('django_language', lang_code)
       
    34     return response