mirror of
https://github.com/django/django.git
synced 2025-10-27 23:56:08 +00:00
Refs #15902 -- Deprecated storing user's language in the session.
This commit is contained in:
@@ -24,6 +24,9 @@ details on these changes.
|
||||
``ugettext_noop()``, ``ungettext()``, and ``ungettext_lazy()`` will be
|
||||
removed.
|
||||
|
||||
* ``django.views.i18n.set_language()`` will no longer set the user language in
|
||||
``request.session`` (key ``django.utils.translation.LANGUAGE_SESSION_KEY``).
|
||||
|
||||
.. _deprecation-removed-in-3.1:
|
||||
|
||||
3.1
|
||||
|
||||
@@ -1106,3 +1106,8 @@ functions without the ``u``.
|
||||
|
||||
Session key under which the active language for the current session is
|
||||
stored.
|
||||
|
||||
.. deprecated:: 3.0
|
||||
|
||||
The language won't be stored in the session in Django 4.0. Use the
|
||||
:setting:`LANGUAGE_COOKIE_NAME` cookie instead.
|
||||
|
||||
@@ -302,6 +302,11 @@ Miscellaneous
|
||||
* ``ContentType.__str__()`` now includes the model's ``app_label`` to
|
||||
disambiguate model's with the same name in different apps.
|
||||
|
||||
* Because accessing the language in the session rather than in the cookie is
|
||||
deprecated, ``LocaleMiddleware`` no longer looks for the user's language in
|
||||
the session and :func:`django.contrib.auth.logout` no longer preserves the
|
||||
session's language after logout.
|
||||
|
||||
.. _deprecated-features-3.0:
|
||||
|
||||
Features deprecated in 3.0
|
||||
@@ -332,6 +337,11 @@ Miscellaneous
|
||||
:func:`~django.utils.translation.ngettext`, and
|
||||
:func:`~django.utils.translation.ngettext_lazy`.
|
||||
|
||||
* To limit creation of sessions and hence favor some caching strategies,
|
||||
:func:`django.views.i18n.set_language` will stop setting the user's language
|
||||
in the session in Django 4.0. Since Django 2.1, the language is always stored
|
||||
in the :setting:`LANGUAGE_COOKIE_NAME` cookie.
|
||||
|
||||
.. _removed-features-3.0:
|
||||
|
||||
Features removed in 3.0
|
||||
|
||||
@@ -1824,20 +1824,8 @@ You may want to set the active language for the current session explicitly. Perh
|
||||
a user's language preference is retrieved from another system, for example.
|
||||
You've already been introduced to :func:`django.utils.translation.activate()`. That
|
||||
applies to the current thread only. To persist the language for the entire
|
||||
session, also modify :data:`~django.utils.translation.LANGUAGE_SESSION_KEY`
|
||||
in the session::
|
||||
|
||||
from django.utils import translation
|
||||
user_language = 'fr'
|
||||
translation.activate(user_language)
|
||||
request.session[translation.LANGUAGE_SESSION_KEY] = user_language
|
||||
|
||||
You would typically want to use both: :func:`django.utils.translation.activate()`
|
||||
will change the language for this thread, and modifying the session makes this
|
||||
preference persist in future requests.
|
||||
|
||||
If you are not using sessions, the language will persist in a cookie, whose name
|
||||
is configured in :setting:`LANGUAGE_COOKIE_NAME`. For example::
|
||||
session in a cookie, set the :setting:`LANGUAGE_COOKIE_NAME` cookie on the
|
||||
response::
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
@@ -1847,6 +1835,14 @@ is configured in :setting:`LANGUAGE_COOKIE_NAME`. For example::
|
||||
response = HttpResponse(...)
|
||||
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language)
|
||||
|
||||
You would typically want to use both: :func:`django.utils.translation.activate()`
|
||||
changes the language for this thread, and setting the cookie makes this
|
||||
preference persist in future requests.
|
||||
|
||||
.. versionchanged:: 3.0
|
||||
|
||||
In older versions, you could set the language in the current session.
|
||||
|
||||
Using translations outside views and templates
|
||||
----------------------------------------------
|
||||
|
||||
@@ -1980,9 +1976,6 @@ following this algorithm:
|
||||
root URLconf. See :ref:`url-internationalization` for more information
|
||||
about the language prefix and how to internationalize URL patterns.
|
||||
|
||||
* Failing that, it looks for the :data:`~django.utils.translation.LANGUAGE_SESSION_KEY`
|
||||
key in the current user's session.
|
||||
|
||||
* Failing that, it looks for a cookie.
|
||||
|
||||
The name of the cookie used is set by the :setting:`LANGUAGE_COOKIE_NAME`
|
||||
|
||||
Reference in New Issue
Block a user