summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-02-29 18:38:44 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-02-29 18:38:44 +0000
commitefed04b6346b5eab4e01af66f9928275521ac30b (patch)
treef57a0dfe4d2d865794f094624e982dfa789e98b6
parent2dbb08e5dc7fe97d912855de530713a4ff7e42c0 (diff)
Fixed #5603 -- Allow customization of the language cookie name. Thanks, moe.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/conf/global_settings.py2
-rw-r--r--django/utils/translation/trans_real.py2
-rw-r--r--django/views/i18n.py2
-rw-r--r--docs/i18n.txt5
-rw-r--r--docs/settings.txt14
5 files changed, 18 insertions, 7 deletions
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 4c25da9942..6be789a853 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -91,8 +91,8 @@ LANGUAGES_BIDI = ("he", "ar", "fa")
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
-
LOCALE_PATHS = ()
+LANGUAGE_COOKIE_NAME = 'django_language'
# Not-necessarily-technical managers of the site. They get broken link
# notifications and other various e-mails.
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index f8a39710b4..11fc3f0920 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -355,7 +355,7 @@ def get_language_from_request(request):
if lang_code in supported and lang_code is not None and check_for_language(lang_code):
return lang_code
- lang_code = request.COOKIES.get('django_language')
+ lang_code = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
if lang_code and lang_code in supported and check_for_language(lang_code):
return lang_code
diff --git a/django/views/i18n.py b/django/views/i18n.py
index cd23ff8777..e420e3d7f7 100644
--- a/django/views/i18n.py
+++ b/django/views/i18n.py
@@ -28,7 +28,7 @@ def set_language(request):
if hasattr(request, 'session'):
request.session['django_language'] = lang_code
else:
- response.set_cookie('django_language', lang_code)
+ response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
return response
NullSource = """
diff --git a/docs/i18n.txt b/docs/i18n.txt
index 78404d4503..bb6cf74ded 100644
--- a/docs/i18n.txt
+++ b/docs/i18n.txt
@@ -547,7 +547,7 @@ following this algorithm:
* First, it looks for a ``django_language`` key in the the current user's
`session`_.
- * Failing that, it looks for a cookie called ``django_language``.
+ * Failing that, it looks for a cookie that is named according to your ``LANGUAGE_COOKIE_NAME`` setting (the default name is: ``django_language``).
* Failing that, it looks at the ``Accept-Language`` HTTP header. This
header is sent by your browser and tells the server which language(s) you
prefer, in order by priority. Django tries each language in the header
@@ -719,7 +719,8 @@ Activate this view by adding the following line to your URLconf::
The view expects to be called via the ``POST`` method, with a ``language``
parameter set in request. If session support is enabled, the view
saves the language choice in the user's session. Otherwise, it saves the
-language choice in a ``django_language`` cookie.
+language choice in a cookie that is by default named ``django_language``
+(the name can be changed through the ``LANGUAGE_COOKIE_NAME`` setting).
After setting the language choice, Django redirects the user, following this
algorithm:
diff --git a/docs/settings.txt b/docs/settings.txt
index 8478e0ce96..ace893f1b5 100644
--- a/docs/settings.txt
+++ b/docs/settings.txt
@@ -579,6 +579,16 @@ in standard language format. For example, U.S. English is ``"en-us"``. See the
.. _internationalization docs: ../i18n/
+LANGUAGE_COOKIE_NAME
+--------------------
+
+Default: ``'django_language'``
+
+The name of the cookie to use for the language cookie. This can be whatever
+you want (but should be different from SESSION_COOKIE_NAME). See the
+`internationalization docs`_ for details.
+
+
LANGUAGES
---------
@@ -822,8 +832,8 @@ SESSION_COOKIE_NAME
Default: ``'sessionid'``
-The name of the cookie to use for sessions. This can be whatever you want.
-See the `session docs`_.
+The name of the cookie to use for sessions. This can be whatever you want (but
+should be different from ``LANGUAGE_COOKIE_NAME``). See the `session docs`_.
SESSION_COOKIE_PATH
-------------------