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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…