Ticket #14825: patch-14825.2.diff

File patch-14825.2.diff, 1.1 KB (added by Vlastimil Zíma, 14 years ago)

Better patch

  • django/middleware/locale.py

    diff --git a/django/middleware/locale.py b/django/middleware/locale.py
    index b5e4949..626fd4f 100644
    a b  
    11"this is the locale selecting middleware that will look at accept headers"
    22
     3from django.conf import settings
    34from django.utils.cache import patch_vary_headers
    45from django.utils import translation
    56
    class LocaleMiddleware(object):  
    1819        request.LANGUAGE_CODE = translation.get_language()
    1920
    2021    def process_response(self, request, response):
     22        if hasattr(request, 'session'):
     23            if not request.session.has_key('django_language'):
     24                request.session['django_language'] = translation.get_language()
     25        else:
     26            # sessions are not used
     27            if not response.cookies.has_key(settings.LANGUAGE_COOKIE_NAME):
     28                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, translation.get_language())
     29
    2130        patch_vary_headers(response, ('Accept-Language',))
    2231        if 'Content-Language' not in response:
    2332            response['Content-Language'] = translation.get_language()
Back to Top