mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Refs #15902 -- Deprecated storing user's language in the session.
This commit is contained in:
parent
76990cbbda
commit
a8e2a9bac6
11 changed files with 94 additions and 57 deletions
|
@ -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`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue