#19811 closed Bug (fixed)
KeyError: u"Unknown language code 'en-us'."
Reported by: | Max Arnold | Owned by: | nobody |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Default LANGUAGE_CODE='en-us' is not present in django.conf.locale.LANG_INFO and can trigger KeyError exception. It can be easily reproduced by using get_language_info in templates. Example project is attached.
Command to reproduce an exception:
curl -v -L http://localhost:8000
Traceback is below:
Internal Server Error: /en-us/ Traceback (most recent call last): File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/core/handlers/base.py", line 140, in get_response response = response.render() File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/response.py", line 105, in render self.content = self.rendered_content File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/response.py", line 82, in rendered_content content = template.render(context) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/base.py", line 140, in render return self._render(context) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/base.py", line 134, in _render return self.nodelist.render(context) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/base.py", line 830, in render bit = self.render_node(node, context) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/templatetags/i18n.py", line 32, in render context[self.variable] = translation.get_language_info(lang_code) File "/Users/lwarx/.virtualenvs/locale/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 150, in get_language_info raise KeyError("Unknown language code %r." % lang_code) KeyError: u"Unknown language code 'en-us'."
Django version was installed from GitHub 1.5.x branch (77f6eb2a6099).
Attachments (1)
Change History (14)
by , 12 years ago
Attachment: | example.zip added |
---|
follow-up: 3 comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.5-rc-1 → master |
I also think that we should fallback to the language code stripped from the country code in this case.
comment:3 by , 12 years ago
Replying to claudep:
I also think that we should fallback to the language code stripped from the country code in this case.
So in this case we should check for 'en' entry in django.conf.locale.LANG_INFO? If yes, I can provide patch with tests.
comment:4 by , 12 years ago
I added fallback in this pull request https://github.com/django/django/pull/777
comment:5 by , 12 years ago
Has patch: | set |
---|
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:8 by , 12 years ago
Resolution: | fixed |
---|---|
Status: | closed → new |
The ticket has been marked as fixed, but the patch has not been applied to the 1.5.x branch. Is there any chance this can be backported to 1.5?
comment:9 by , 12 years ago
I hoped it would be included into 1.5 release... Is it possible to backport this fix to 1.5.x branch for next minor release?
comment:10 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
It looks like patch was superseded by 8c8f94fe9dcdd4983ebeb59951e6f7399bc287a2 in ticket #19763
comment:11 by , 11 years ago
language problem in some browsers
u"Unknown language code 'es-co'."
django = 1.5.1
comment:12 by , 11 years ago
u"Unknown language code 'en-us'."
django = 1.5.1
Works, when 'en-us' is replaced by just 'en'.
settings.py:
LANGUAGES = ( ('en-us', ugettext('English')), ('uk', ugettext('Ukrainian')), )
comment:13 by , 11 years ago
Am still getting this in 1.5.3, too:
LANGUAGES = ( # See http://www.i18nguy.com/unicode/language-identifiers.html, but all lower case ('en-gb', _fake_gettext('UK English')), ('en-us', _fake_gettext('US English')), ) LANGUAGE_CODE = 'en-gb'
example project to reproduce the problem