Statistics
| Branch: | Tag: | Revision:

root / ui / i18n.py @ f533f224

History | View | Annotate | Download (857 Bytes)

1
from django import http
2
from django.conf import settings
3
from django.utils.translation import activate, to_locale
4
from django.utils.translation import check_for_language, get_language
5

    
6
def set_language(request):
7
    """
8
    Django's set_language function adapted to serve GET instead of POST
9
    """
10
    next = request.REQUEST.get('next', None)
11
    if not next:
12
        next = request.META.get('HTTP_REFERER', None)
13
    if not next:
14
        next = '/'
15
    response = http.HttpResponseRedirect(next)
16
    if request.method == 'GET':
17
        lang_code = request.GET.get('l', None)
18
        if lang_code and check_for_language(lang_code):
19
            if hasattr(request, 'session'):
20
                request.session['django_language'] = lang_code
21
            else:
22
                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
23
    return response