Code

Ticket #14825: patch-14825.2.diff

File patch-14825.2.diff, 1.1 KB (added by vzima, 3 years ago)

Better patch

Line 
1diff --git a/django/middleware/locale.py b/django/middleware/locale.py
2index b5e4949..626fd4f 100644
3--- a/django/middleware/locale.py
4+++ b/django/middleware/locale.py
5@@ -1,5 +1,6 @@
6 "this is the locale selecting middleware that will look at accept headers"
7 
8+from django.conf import settings
9 from django.utils.cache import patch_vary_headers
10 from django.utils import translation
11 
12@@ -18,6 +19,14 @@ class LocaleMiddleware(object):
13         request.LANGUAGE_CODE = translation.get_language()
14 
15     def process_response(self, request, response):
16+        if hasattr(request, 'session'):
17+            if not request.session.has_key('django_language'):
18+                request.session['django_language'] = translation.get_language()
19+        else:
20+            # sessions are not used
21+            if not response.cookies.has_key(settings.LANGUAGE_COOKIE_NAME):
22+                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, translation.get_language())
23+
24         patch_vary_headers(response, ('Accept-Language',))
25         if 'Content-Language' not in response:
26             response['Content-Language'] = translation.get_language()