Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13602 closed (invalid)

path for fix hardcode 'django_language'

Reported by: ablis Owned by: nobody
Component: Internationalization Version: 1.2
Severity: Keywords: LANGUAGE_COOKIE_NAME
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

django/utils/translation/trans_real.py and django/views/i18n.py b/django/views/i18n.py have some hardcode sessiondjango_language?.
It will be some problem with language in admin if change settings.LANGUAGE_COOKIE_NAME. I attached path for fix that.

Attachments (1)

django_language.path (1.2 KB) - added by ablis 4 years ago.

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by ablis

comment:1 Changed 4 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

I think you are confusing the _cookie_ name with the _session_ key name. LANGUAGE_COOKIE_NAME is correctly used when setting or getting the actual cookie. The session key name is hardcoded to django_language; but changing LANGUAGE_COOKIE_NAME will not affect that, and should not cause any problems with language in the admin.

If you are seeing a problem when changing LANGUAGE_COOKIE_NAME, please post more detailed duplication instructions.

comment:2 follow-up: Changed 4 years ago by ablis

  • Resolution invalid deleted
  • Status changed from closed to reopened

I'm sorry, do you like hardcode?
request.sessiondjango_language? and request.session[settings.LANGUAGE_COOKIE_NAME] is equivalent,
but, for example, if you make in your settings.LANGUAGE_COOKIE_NAME = "site_language"?
code like that:

if hasattr(request, 'session'):

lang_code = request.session.get('django_language', None)

will not work. Because it's absolutely hardcode... And your admin language will not be changed...

comment:3 in reply to: ↑ 2 Changed 4 years ago by carljm

  • Resolution set to invalid
  • Status changed from reopened to closed

Replying to ablis:

code like that:

if hasattr(request, 'session'):

lang_code = request.session.get('django_language', None)

will not work. Because it's absolutely hardcode... And your admin language will not be changed...

Have you actually tried setting LANGUAGE_COOKIE_NAME and seen something break?

I don't think you read or understood my first response.

By default, Django uses the session to store your language preference. If contrib.sessions is not installed, it falls back to using a cookie. The two systems are entirely separate, and the cookie system is only used if you don't have sessions available.

In the case of using the session, the session key name is hard-coded to "django_language." In the case of using the cookie, the cookie name is the value of LANGUAGE_COOKIE_NAME. A cookie name is visible to the site user, so there are valid use-cases for wanting to change it. A session key name is server-side-only, so there's no need to change it.

If you think that the session key name should _also_ be configurable with a setting, that would be a separate setting, and you would need to bring that up as a feature request on the django-developers mailing list, with a use-case that justifies the need.

Having LANGUAGE_COOKIE_NAME double also as a session key name, as your patch does, makes no sense: the name of the setting clearly indicates that it is a _cookie_ name.

Please don't reopen this ticket again unless you can provide step-by-step instructions for how to reproduce an actual observable problem.

comment:4 Changed 4 years ago by ablis

Oops... Sorry for waste your time. My mistake... different constants with the same name.

comment:5 Changed 4 years ago by ablis

And for the end. My opinion is that add on the default settings the constant like SESSION_LANGUAGE_NAME ='django_language' will be more correct.

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.