Opened 7 years ago

Closed 6 years ago

Last modified 4 years ago

#7720 closed (fixed)

LocaleMiddleware doesn't fallback to the first part of the language code when it's received from the user's browser in a cookie

Reported by: djoume Owned by: ramiro
Component: Internationalization Version: master
Severity: Keywords: cookie fallback language sublanguage root language
Cc: dsalvetti@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi,

I have a project where the language cookie is set by another system (under the same domain).

This system set the LANGUAGE_COOKIE to 'fr-ca' or 'en-us'.

I have in my settings file:

LANGUAGES = ( 
    ('en', ugettext('English')),
    ('fr', ugettext('French')),
)

According to the documentation, this should restrict languages that are available for automatic selection to French and English (and any sublanguage, like fr-ca or en-us).

This is true when the language is set in the HTTP Header (ie fr-ca matches fr) but not when the language is set in the LANGUAGE_COOKIE by another system.

The attached patch is a tentative to fix this (it works for me).

Attachments (3)

fallback_to_first_part_of_language_code_of_cookie.diff (674 bytes) - added by djoume 7 years ago.
7720-fallback-to-root-lang-when-lang-pref-stored-in-cookie.diff (2.9 KB) - added by ramiro 6 years ago.
Patch with original fix by djoume plus tests
7720-fallback-to-root-lang-when-lang-pref-stored-in-cookie.2.diff (3.1 KB) - added by ramiro 6 years ago.
Better fix: Don't assume root language name has a length of two, RC2616 says it can be up to eight chars long

Download all attachments as: .zip

Change History (7)

comment:1 Changed 7 years ago by serialx

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

Looks good to me. I think we need some tests? (Is there any tests to test that?)

Changed 6 years ago by ramiro

Patch with original fix by djoume plus tests

comment:2 Changed 6 years ago by ramiro

  • Keywords cookie fallback language sublanguage root language added
  • milestone set to 1.2
  • Needs tests unset
  • Owner changed from nobody to ramiro
  • Summary changed from LocaleMiddleware doesn't fallback to the first part of the language code. to LocaleMiddleware doesn't fallback to the first part of the language code when it's received from the user's browser in a cookie

Changed 6 years ago by ramiro

Better fix: Don't assume root language name has a length of two, RC2616 says it can be up to eight chars long

comment:3 Changed 6 years ago by jezdez

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

(In [12452]) [1.1.X] Fixed #7720 - Fallback to the base language if the sub language given in the language cookie doesn't exist. Thanks, djoume and Ramiro Morales.

Backport of r12442.

comment:4 Changed 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top