#16449: i18n_pattern URLs reversed from shell and tests have incorrect language
prefix
-------------------------------------------------+-------------------------
Reporter: jakub | Owner: nobody
Type: Bug | Status: new
Milestone: | Component:
Version: SVN | Translations
Keywords: urlconf, reverse, i18n_patterns, | Severity: Normal
tests, shell | Triage Stage:
Has patch: 0 | Unreviewed
UI/UX: 0 | Easy pickings: 0
-------------------------------------------------+-------------------------
I've been trying out the new `i18n_patterns` from trunk and have run into
the following issue:
The `django.core.urlresolvers.reverse()` function always returns `/en-us`
as the language prefix for i18n URLs when it is called from a shell
session or tests. I don't have `en-us` in my `settings.LANGUAGES` so
requests to such URLs result in 404s.
After some digging I've found out that the above is probably just a
symptom of another issue which is that the language specified in
`settings.LANGUAGE_CODE` isn't automatically activated for shell sessions
and when running tests:
{{{
$ ./manage.py shell
>>> from django.conf import settings
>>> settings.LANGUAGE_CODE
'es'
>>> from django.utils import translation
>>> translation.get_language()
'en-us'
>>> from django.core.urlresolvers import reverse
>>> reverse('test')
'/en-us/'
}}}
I've also tried adding `en-us` as `settings.LANGUAGE_CODE` and to
`settings.LANGUAGES`, after which I was able to run my tests, but there
was another issue: the `get_language_info` template tag raises an
exception when the language code is `en-us`, because it isn't defined in
`django.conf.locale.LANG_INFO`:
{{{
$ ./manage.py shell
>>> from django.utils import translation
>>> translation.get_language_info('en-us')
---------------------------------------------------------------------------
KeyError Traceback (most recent call
last)
django/utils/translation/__init__.pyc in get_language_info(lang_code)
165 from django.conf.locale import LANG_INFO
166 try:
167 return LANG_INFO[lang_code]
168 except KeyError:
--> 169 raise KeyError("Unknown language code %r." % lang_code)
KeyError: "Unknown language code 'en-us'."
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/16449>
Django <https://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.