#8626: Translations from "en_US" locale being used even though
request.LANGUAGE_CODE is "en"
-------------------------------------------+--------------------------------
Reporter: francisoreilly | Owner: nobody
Status: new | Milestone: 1.0
Component: Internationalization | Version: SVN
Resolution: | Keywords: locale language
en-us en-US
Stage: Accepted | Has_patch: 0
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------------+--------------------------------
Comment (by arien):
Okay, that was fun... This is a problem in Python's `locale` module,
where (basically) `en` is mapped to `en_US` in the `locale.locale_alias`
dict. This in turn causes the wrong `.mo` file to be loaded.
In detail: `gettext.translation` (which is used in
`django.utils.translation.trans_real.translation`) calls `gettext.find` to
locate the correct `.mo` file to load, which calls (the misnamed)
`gettext._expand_lang` (`gettext._expand_lang` returns a list of possible
locale names for the given locale). Finally, `gettext._expand_lang` calls
`locale.normalize` for the normalized name of a locale, and
`locale.normalize` uses the `locale.locale_alias` dict. And it just so
happens that `en` is mapped to `en_US.ISO8859-1`...
{{{
>>> import gettext
>>> gettext.find('django', 'locale', ['en'], all=1)
['locale/en_US/LC_MESSAGES/django.mo', 'locale/en/LC_MESSAGES/django.mo']
>>> gettext._expand_lang('en')
['en_US.ISO8859-1', 'en_US', 'en.ISO8859-1', 'en']
>>>
>>> # Monkey patch our way out of trouble.
>>> import locale
>>> locale.locale_alias['en'] = 'en.ISO8859-1'
>>> gettext.find('django', 'locale', ['en'], all=1)
['locale/en/LC_MESSAGES/django.mo']
>>> gettext._expand_lang('en')
['en.ISO8859-1', 'en']
}}}
(The output is from a session in the project directory.)
I'll attach a patch.
--
Ticket URL: <http://code.djangoproject.com/ticket/8626#comment:6>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---