Opened 8 years ago

Closed 7 years ago

Last modified 5 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 Salvetti Owned by: Ramiro Morales
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 Salvetti 8 years ago.
7720-fallback-to-root-lang-when-lang-pref-stored-in-cookie.diff (2.9 KB) - added by Ramiro Morales 7 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 Morales 7 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)

Changed 8 years ago by Djoume Salvetti

comment:1 Changed 8 years ago by Sung-jin Hong

Needs tests: set
Triage Stage: UnreviewedAccepted

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

Changed 7 years ago by Ramiro Morales

Patch with original fix by djoume plus tests

comment:2 Changed 7 years ago by Ramiro Morales

Keywords: cookie fallback language sublanguage root language added
milestone: 1.2
Needs tests: unset
Owner: changed from nobody to Ramiro Morales
Summary: LocaleMiddleware doesn't fallback to the first part of the language code.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 7 years ago by Ramiro Morales

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 7 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

(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 5 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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