I have an existing multi-lingual Django app that I'm porting to Django 1.4. I18n support is currently based on some ugly hacks, I'd like to make it use Django's built-in i18n modules.
One constraint is that I don't want to change the urls that are already in place. This site has been active for a while and there are external links to it that I dont' want to break or redirect. The urls scheme works like this: English content is at the root of the site, while other languages use prefixes in the domain name:
English urls:
/
/articles/
/suggestions/
Spanish urls:
/es/
/es/articulos/
/es/sugerencias/
I've got the translated pages working with Django 1.4's i18n modules, but it really, really, really wants to put all the English urls under /en/. I've tried a few different hacks, including defining non-internationalized urls for the English version:
def build(callback):
return callback('',
url(_(r'^$'), home.index, name="home"),
url(_(r'^articles/$'), content.article_list, name='article_list'),
url(_(r'^suggestions/$'), suggestions.suggestions, name='suggestions'),
)
urlpatterns = build(patterns)
urlpatterns += build(i18n_patterns)
This makes the urls resolve properly, but the {% url %} tag to do reverse resolution doesn't work.
What's the best way to accomplish non-prefixed English-language urls?
_
the non-lazy version fo gettext? i.e.from django.utils.translation import ugettext as _
– Din