Opened 5 years ago

Closed 5 years ago

Last modified 20 months ago

#17569 closed New feature (duplicate)

i18n_patterns and set_language

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: 1.4-alpha-1
Severity: Normal Keywords: i18n_patterns, set_language
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: no UI/UX: no



I wrote some code to set language with support for i18n_patterns.

from urlparse import urlparse

from django import http
from django.conf import settings
from django.utils import translation
from django.core.urlresolvers import resolve, reverse
from django.utils.translation import check_for_language

def set_language(request):
    next = request.REQUEST.get('next', None)
    if not next:
        next = request.META.get('HTTP_REFERER', None)
    if not next:
        next = '/'

    url = urlparse(next)

        r = resolve(url.path)
        next = '/'

    response = http.HttpResponseRedirect(next)
    lang_code = request.GET.get('language', None)

    if lang_code and check_for_language(lang_code):
            next = reverse('%s:%s' % (r.namespace, r.url_name), args=r.args, kwargs=r.kwargs)
            response = http.HttpResponseRedirect(next)

        if hasattr(request, 'session'):
            request.session['django_language'] = lang_code
            response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)

    return response

Change History (4)

comment:1 Changed 5 years ago by Wiktor

Needs documentation: set
Needs tests: set
Patch needs improvement: unset

comment:2 Changed 5 years ago by Tomek Paczkowski

Resolution: needsinfo
Status: newclosed

This issue quite unspecified. I can't tell what is this about. Closing as needs more info.

comment:3 Changed 5 years ago by Łukasz Rekucki

Has patch: unset

If I understand correctly, this is a proposition to make set_language view translate the next it gets. I don't know if adding an extra resolve() is a good idea. Maybe someone can some up with a cleaner solution. Either way, this needs an *actual patch* (in form of a diff against trunk) including tests for new behavior and documentation of the change.

comment:4 Changed 20 months ago by Claude Paroz

Resolution: needsinfoduplicate

Set as duplicate for #24122

Note: See TracTickets for help on using tickets.
Back to Top