Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #5603 -- Allow customization of the language cookie name. Thank…

…s, moe.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit efed04b6346b5eab4e01af66f9928275521ac30b 1 parent 2dbb08e
Malcolm Tredinnick authored February 29, 2008
2  django/conf/global_settings.py
@@ -91,8 +91,8 @@
91 91
 # If you set this to False, Django will make some optimizations so as not
92 92
 # to load the internationalization machinery.
93 93
 USE_I18N = True
94  
-
95 94
 LOCALE_PATHS = ()
  95
+LANGUAGE_COOKIE_NAME = 'django_language'
96 96
 
97 97
 # Not-necessarily-technical managers of the site. They get broken link
98 98
 # notifications and other various e-mails.
2  django/utils/translation/trans_real.py
@@ -355,7 +355,7 @@ def get_language_from_request(request):
355 355
         if lang_code in supported and lang_code is not None and check_for_language(lang_code):
356 356
             return lang_code
357 357
 
358  
-    lang_code = request.COOKIES.get('django_language')
  358
+    lang_code = request.COOKIES.get(settings.LANGUAGE_COOKIE_NAME)
359 359
     if lang_code and lang_code in supported and check_for_language(lang_code):
360 360
         return lang_code
361 361
 
2  django/views/i18n.py
@@ -28,7 +28,7 @@ def set_language(request):
28 28
             if hasattr(request, 'session'):
29 29
                 request.session['django_language'] = lang_code
30 30
             else:
31  
-                response.set_cookie('django_language', lang_code)
  31
+                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
32 32
     return response
33 33
 
34 34
 NullSource = """
5  docs/i18n.txt
@@ -547,7 +547,7 @@ following this algorithm:
547 547
 
548 548
     * First, it looks for a ``django_language`` key in the the current user's
549 549
       `session`_.
550  
-    * Failing that, it looks for a cookie called ``django_language``.
  550
+    * Failing that, it looks for a cookie that is named according to your ``LANGUAGE_COOKIE_NAME`` setting (the default name is: ``django_language``).
551 551
     * Failing that, it looks at the ``Accept-Language`` HTTP header. This
552 552
       header is sent by your browser and tells the server which language(s) you
553 553
       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::
719 719
 The view expects to be called via the ``POST`` method, with a ``language``
720 720
 parameter set in request. If session support is enabled, the view
721 721
 saves the language choice in the user's session. Otherwise, it saves the
722  
-language choice in a ``django_language`` cookie.
  722
+language choice in a cookie that is by default named ``django_language``
  723
+(the name can be changed through the ``LANGUAGE_COOKIE_NAME`` setting).
723 724
 
724 725
 After setting the language choice, Django redirects the user, following this
725 726
 algorithm:
14  docs/settings.txt
@@ -579,6 +579,16 @@ in standard language format. For example, U.S. English is ``"en-us"``. See the
579 579
 
580 580
 .. _internationalization docs: ../i18n/
581 581
 
  582
+LANGUAGE_COOKIE_NAME
  583
+--------------------
  584
+
  585
+Default: ``'django_language'``
  586
+
  587
+The name of the cookie to use for the language cookie. This can be whatever
  588
+you want (but should be different from SESSION_COOKIE_NAME). See the
  589
+`internationalization docs`_ for details.
  590
+
  591
+
582 592
 LANGUAGES
583 593
 ---------
584 594
 
@@ -822,8 +832,8 @@ SESSION_COOKIE_NAME
822 832
 
823 833
 Default: ``'sessionid'``
824 834
 
825  
-The name of the cookie to use for sessions. This can be whatever you want.
826  
-See the `session docs`_.
  835
+The name of the cookie to use for sessions. This can be whatever you want (but
  836
+should be different from ``LANGUAGE_COOKIE_NAME``). See the `session docs`_.
827 837
 
828 838
 SESSION_COOKIE_PATH
829 839
 -------------------

0 notes on commit efed04b

Please sign in to comment.
Something went wrong with that request. Please try again.