Statistics
| Branch: | Tag: | Revision:

root / ui / i18n.py @ 800ee222

History | View | Annotate | Download (821 Bytes)

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

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