Translations from "en_US" locale being used even though request.LANGUAGE_CODE is "en"
|Reported by:||francisoreilly||Owned by:||nobody|
|Severity:||Normal||Keywords:||locale language en-us en-US|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
I've got a situation where even though the template has request.LANGUAGE_CODE=="en", the "en_US" translations are being rendered instead of the "en" translations. Furthermore, if request.LANGUAGE_CODE=="en-gb", the "en_GB" translation is being pulled back, correctly. In summary:
- if LANGUAGE_CODE=="en" -> pulls back "en_US" translations (incorrect)
- if LANGUAGE_CODE=="en-gb" -> pulls back "en_GB" translations (expected result)
- if LANGUAGE_CODE=="en-us" -> pulls back "en_US" translations (expected result)
To demonstrate the problem I put together and attached a tar.gz of a simple project directory:
- A homepage that has a dropdown control for selecting/setting the user's chosen language, choices are "en", "en-gb" and "en-us". The form sets the request.LANGUAGE_CODE via the set-language view (django.conf.urls.i18n). urls.py is setup to activate the set-language view when user clicks Submit. The homepage itself lives at /index.html/
- Three locale translations corresponding, i.e. "en", "en_GB" and "en_US" in the locale subdir. I've localized the text "Homepage" with different text strings for each of the three locales. django.po
- A settings.py which specifies the three LANGUAGES, a LANGUAGE_CODE of "en". It also pulls in the LocaleMiddleware as is necessary for locale translations.
I think the other settings/files included are not relevant to the problem (e.g. the sqlite_db database file, etc), they're only included to form a runnable project.
I've been able to show this behaviour in 1.0-beta_2-SVN-8643 - simply go to the homepage at /index.html/ and choose the different language values and submit. The page refreshes to show the current value of request.LANGUAGE_CODE and also which translation has been pulled back.
Change History (16)
comment:11 Changed 6 years ago by