Opened 16 years ago

Closed 14 years ago

Last modified 12 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: dev
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: no UI/UX: no

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 16 years ago.
7720-fallback-to-root-lang-when-lang-pref-stored-in-cookie.diff (2.9 KB ) - added by Ramiro Morales 14 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 14 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 by Sung-jin Hong, 16 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

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

by Ramiro Morales, 14 years ago

Patch with original fix by djoume plus tests

comment:2 by Ramiro Morales, 14 years ago

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

by Ramiro Morales, 14 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

comment:3 by Jannis Leidel, 14 years ago

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 by Jacob, 12 years ago

milestone: 1.2

Milestone 1.2 deleted

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