[Django]-Django urlpatterns translated with ugettext lazy – if 404 how to check again if url matches for another language?

0👍

I don’t really like the idea of translating the URLs, but try something like this:

en/django.po:

msgid "^contact/"
msgstr "^en/contact/"

msgid "^wrong_lang/(?P<url_part>.+)"
msgstr "^ru/(?P<url_part>.+)"

urls.py:

url(_(r'^contact/'), include('contact.urls')), # matches "en/contact/" URL
url(_(r'^wrong_lang/(?P<url_part>.+)', redirect_to_current_lang), # matches "ru/..." URLs

views.py:

def redirect_to_current_lang(request, url_part):
   return HttpResponseRedirect(_('^%s' % url_part))

Leave a comment