Commits

Nuno Mariz committed bf45b89

Added locale to user session when 'change_locale' view is called

  • Participants
  • Parent commits a5d7fcf

Comments (0)

Files changed (2)

File localeurl/middleware.py

 
     def process_request(self, request):
         locale, path = utils.strip_path(request.path_info)
+
+        if not locale and hasattr(request, 'session'):
+            locale = request.session.get('django_language', None)
+
         if localeurl_settings.USE_ACCEPT_LANGUAGE and not locale:
             accept_langs = filter(lambda x: x, [utils.supported_language(lang[0])
                                                 for lang in
                         request.META.get('HTTP_ACCEPT_LANGUAGE', ''))])
             if accept_langs:
                 locale = accept_langs[0]
+
+        if not locale:
+            locale = settings.LANGUAGE_CODE
+
         locale_path = utils.locale_path(path, locale)
         if locale_path != request.path_info:
             if request.META.get("QUERY_STRING", ""):

File localeurl/views.py

         locale = request.POST.get('locale', None)
         if locale and check_for_language(locale):
             path = utils.locale_path(path, locale)
+            if hasattr(request, 'session'):
+                request.session['django_language'] = locale
+            else:
+                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, locale)
 
     response = http.HttpResponseRedirect(path)
     return response