Code

Opened 3 years ago

Closed 7 weeks ago

#15318 closed New feature (fixed)

A possibility to configure the language's cookie domain and expires.

Reported by: sahid Owned by: sergeykolosov
Component: Internationalization Version: 1.2
Severity: Normal Keywords: cookie, domain, language, settings
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hello,

A suggest a new settings: LANGUAGE_COOKIE_DOMAIN

Index: conf/global_settings.py
===================================================================
--- conf/global_settings.py	(revision 15552)
+++ conf/global_settings.py	(working copy)
@@ -112,6 +112,8 @@
 USE_I18N = True
 LOCALE_PATHS = ()
 LANGUAGE_COOKIE_NAME = 'django_language'
+LANGUAGE_COOKIE_DOMAIN = None
+LANGUAGE_COOKIE_EXPIRES = None
 
 # If you set this to True, Django will format dates, numbers and calendars
 # according to user current locale
Index: views/i18n.py
===================================================================
--- views/i18n.py	(revision 15552)
+++ views/i18n.py	(working copy)
@@ -32,7 +32,11 @@
             if hasattr(request, 'session'):
                 request.session['django_language'] = lang_code
             else:
-                response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code)
+                response.set_cookie(
+                    settings.LANGUAGE_COOKIE_NAME,
+                    lang_code,
+                    expires=settings.LANGUAGE_COOKIE_EXPIRES,
+                    domain=settings.LANGUAGE_COOKIE_DOMAIN)
     return response
 
 def get_formats():

Attachments (0)

Change History (11)

comment:1 Changed 3 years ago by russellm

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

Patch needs to be attached as a diff, rather than as a comment. It also requires tests.

comment:2 Changed 3 years ago by ramiro

  • Component changed from Translations to Internationalization

comment:3 Changed 3 years ago by lrekucki

  • Severity set to Normal
  • Type set to New feature

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 11 months ago by sergeykolosov

  • Owner changed from nobody to sergeykolosov
  • Status changed from new to assigned

comment:7 Changed 11 months ago by sergeykolosov

  • Needs tests unset
  • Patch needs improvement unset

Pull request: https://github.com/django/django/pull/1150

For the sake of consistency I've added the following settings: LANGUAGE_COOKIE_AGE, LANGUAGE_COOKIE_PATH and LANGUAGE_COOKIE_DOMAIN.

comment:8 Changed 7 months ago by ramiro

This could be solved without introducing additional top-level settings if/after #21051 lands.

comment:9 Changed 2 months ago by timo

  • Patch needs improvement set

I've left comments for improvement on the PR. Please uncheck "Patch needs improvement" when it's updated.

comment:10 Changed 8 weeks ago by sergeykolosov

  • Patch needs improvement unset

comment:11 Changed 7 weeks ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 8c98f39624a60c63a16e097b64e5f71ecc27271f:

Fixed #15318 -- Added settings for language cookie max-age, path, domain

Introduced a number of settings to configure max-age, path, and domain
for the language cookie: LANGUAGE_COOKIE_AGE, LANGUAGE_COOKIE_PATH and
LANGUAGE_COOKIE_DOMAIN.

Thanks sahid for the suggestion.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.