Opened 5 years ago

Last modified 4 years ago

#15902 new New feature

Storing current language in session/cookie

Reported by: msiedlarek Owned by: msiedlarek
Component: Internationalization Version: 1.3
Severity: Normal Keywords: language i18n session cookie
Cc: msiedlarek, raymond.penners@…, vlastimil.zima@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by lukeplant)

Related discussion

Problem summary

The problem is that even for non-logged users their language is stored in session (if it's supported or in the cookie otherwise). That creates a session for every client, which makes serving static (ofc I mean static, but not media) content through an upstream cache (such as Squid) really inefficient. I suppose selected language is not that secret to protect it by storing in session, and cookie is just ok. For cookie-varying cache it's a huge difference.

Solution proposal

There is a setting named LANGUAGE_COOKIE_NAME which never gets used if you use session based cookies. The file cookie is just never saved. But if there were an option to save data in the session and also save the LANGUAGE_COOKIE as a file separately - then it would also persist after logout and solve the issue with languages after the session gets destroyed.


I would propose to have the set_language() view with options to set it as a file based cookie or a session.


It would allow the language file based cookie to have a very long expire date and the session would still be usable for storing secure data.

Change History (4)

comment:1 Changed 5 years ago by lukeplant

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

This is proposing the same thing as #12794, but for a different reason.

#13217 is related, but the solution proposed here was not proposed there, and doesn't have the same issues that caused the WONTFIX on that ticket. This change would help that problem if the cache is able to cache by language cookie.

I'm not in favour of yet another setting if we can avoid it - we need to know if there are any downsides to always storing in the cookie rather than the session. If not, we always store in the cookie. Since we've documented the current behaviour, we may however need a deprecation path involving a setting.

comment:2 Changed 5 years ago by msiedlarek

I propose we discuss on this strictly on django-developers to avoid general mess and redundancy.

comment:3 Changed 5 years ago by raymond.penners@…

  • Cc raymond.penners@… added

comment:4 Changed 4 years ago by vzima

  • Cc vlastimil.zima@… added
  • UI/UX unset
Note: See TracTickets for help on using tickets.
Back to Top