Commit 0d0f4f02 authored by Bouke Haarsma's avatar Bouke Haarsma Committed by Tim Graham
Browse files

Fixed #5789 -- Changed LocaleMiddleware session variable to '_language'.

The old 'django_language' variable will still be read from in order
to migrate users. The backwards-compatability shim will be removed in
Django 1.8.

Thanks to jdunck for the report and stugots for the initial patch.
parent 8e2029f8
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -56,8 +56,14 @@ class LocaleMiddleware(object):
                return self.response_redirect_class(language_url)

        # Store language back into session if it is not present
        if hasattr(request, 'session'):
            request.session.setdefault('django_language', language)
        if hasattr(request, 'session') and '_language' not in request.session:
            # Backwards compatibility check on django_language (remove in 1.8);
            # revert to: `request.session.setdefault('_language', language)`.
            if 'django_language' in request.session:
                request.session['_language'] = request.session['django_language']
                del request.session['django_language']
            else:
                request.session['_language'] = language

        if not (self.is_language_prefix_patterns_used()
                and language_from_path):
+2 −1
Original line number Diff line number Diff line
@@ -426,7 +426,8 @@ def get_language_from_request(request, check_path=False):
            return lang_code

    if hasattr(request, 'session'):
        lang_code = request.session.get('django_language', None)
        # for backwards compatibility django_language is also checked (remove in 1.8)
        lang_code = request.session.get('_language', request.session.get('django_language'))
        if lang_code in supported and lang_code is not None and check_for_language(lang_code):
            return lang_code

+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ def set_language(request):
        lang_code = request.POST.get('language', None)
        if lang_code and check_for_language(lang_code):
            if hasattr(request, 'session'):
                request.session['django_language'] = lang_code
                request.session['_language'] = lang_code
            else:
                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
    return response
+3 −0
Original line number Diff line number Diff line
@@ -410,6 +410,9 @@ these changes.
* The ``Model._meta.get_(add|change|delete)_permission`` methods will
  be removed.

* The session key ``django_language`` will no longer be read for backwards
  compatibility.

1.9
---

+7 −0
Original line number Diff line number Diff line
@@ -302,6 +302,13 @@ Internationalization
* The :attr:`django.middleware.locale.LocaleMiddleware.response_redirect_class`
  attribute allows you to customize the redirects issued by the middleware.

* The :class:`~django.middleware.locale.LocaleMiddleware` now stores the user's
  selected language with the session key ``_language``. Previously it was
  stored with the key ``django_language``, but keys reserved for Django should
  start with an underscore. For backwards compatibility ``django_language`` is
  still read from in 1.7. Sessions will be migrated to the new ``_language``
  key as they are written.

Management Commands
^^^^^^^^^^^^^^^^^^^

Loading