Commits

Konstantinos Pachnis committed 14b7295

Updated change_locale method to store the language code in either session or cookie. The code is based on django i18n change_local method.

Comments (0)

Files changed (1)

localeurl/views.py

     The url and the locale code need to be specified in the
     request parameters.
     """
+    response = None
+
     next = request.REQUEST.get('next', None)
     if not next:
         next = urlsplit(request.META.get('HTTP_REFERER', None))[2]
         next = '/'
     _, path = utils.strip_path(next)
     if request.method == 'POST':
-        locale = request.POST.get('locale', None)
-        if locale and check_for_language(locale):
-            path = utils.locale_path(path, locale)
+        lang_code = request.POST.get('language', None)
+        if lang_code and check_for_language(lang_code):
+            path = utils.locale_path(path, lang_code)
+            response = http.HttpResponseRedirect(path)
+            if hasattr(request, 'session'):
+                request.session['django_language'] = lang_code
+            else:
+                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
 
-    response = http.HttpResponseRedirect(path)
     return response
+