Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#11585 closed New feature (fixed)

i18n in

Reported by: digi604 Owned by: jezdez
Component: Internationalization Version: master
Severity: Normal Keywords:
Cc: patrick.lauber@…, osirius@…, jonas.obrist@…, info@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Because search engines not only search in english we normally "translate" the urls as well to get higher pageranks in the sites languages.
This is very cumbersome at the moment with django.


en: /contact/
de: /kontakt/
it: /contatto/

they all point to the same view.

it would be nice to have a i18n_url() that would resolve based on the current language.

i18n_url({'de':r'^kontakt/', 'en':r'^contact/', 'it':r'^contatto/'}, contact, name="contact"}

it would be nice to be able to tell reverse() and {% url %} which language to resolve.

{% url contact de %}

reverse('contact', language="de")

If no language is defined it should take the current one from get_language()

Attachments (1)

i18nurls.diff (34.3 KB) - added by brocaar 5 years ago.
Implementation for language-prefix and internationalization of URL patterns

Download all attachments as: .zip

Change History (18)

comment:1 Changed 7 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by thejaswi_puthraya

  • Component changed from Uncategorized to Internationalization

comment:3 Changed 6 years ago by jezdez

  • milestone changed from 1.2 to 1.3

Moving to 1.3 since this is certainly a new feature and we are in bugfix only mode.

comment:4 Changed 6 years ago by anonymous

Great idea. It also requires adding the language code to the URL to ensure that the URL is unique for each language. So the example must create the following URLs:




comment:5 Changed 6 years ago by jezdez

This is somewhat related to #9333, which proposes adding a note about django-localeurl to the documentation.

comment:6 Changed 6 years ago by trebor74hr

Can this be used (it doesn't report error on my place):

    (r'^%s/%s/...$' % (settings.LANGUAGE_CODE, _(u"contact")), view ...

it should produce translated and prefixed urls like:

  • /en-us/contact/...
  • /de/kontakt/...

Or you need more general solution?

comment:8 Changed 6 years ago by SamBull

  • Cc osirius@… added

I'm the maintainer of transurlvania. I think it solves the problem raised in this ticket. I'd like more feedback before I propose including it wholesale as a patch.

comment:9 Changed 6 years ago by jezdez

  • milestone 1.3 deleted
  • Triage Stage changed from Design decision needed to Accepted

Removing the 1.3 milestone for now, since I don't see a chance to get this ready in time. But for what it's worth, I think adopting a few of transurlvania's tools and/or document the technique is worthwhile for future releases.

comment:10 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:11 Changed 5 years ago by brocaar

  • Easy pickings unset
  • Owner changed from nobody to brocaar
  • Status changed from new to assigned
  • UI/UX unset

comment:12 Changed 5 years ago by ojii

  • Cc jonas.obrist@… added

Changed 5 years ago by brocaar

Implementation for language-prefix and internationalization of URL patterns

comment:13 Changed 5 years ago by brocaar

  • Cc info@… added
  • Has patch set
  • milestone set to 1.4
  • Owner changed from brocaar to jezdez
  • Status changed from assigned to new

I have added a patch which contains the following:

  • Implementation of language-prefixing (and detection by LocaleMiddleware) and translation of URL patterns
  • Documentation update
  • Unittests

comment:14 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16405]:

Fixed #11585 -- Added ability to translate and prefix URL patterns with a language code as an alternative method for language discovery. Many thanks to Orne Brocaar for his initial work and Carl Meyer for feedback.

comment:15 Changed 5 years ago by jakub

Thanks for this new feature.

Are there any plans to include also an i18n-aware version of the {% url %} template tag? I know that it will work fine for the current language, but when one needs a URL of a page in another language, then the existing tag doesn't help. It would be great if there was also an option to get a URL of the current page in another language without having to specify it or its name as well. I'm aware of django.views.i18n.set_language() but a link is often needed for search engines to be able to discover the page.

This is a general problem applying also to reverse() but there I suppose you can work it around by activating another language, reversing the URL and then switching back.

I'm willing to provide a patch for the template tag if there is any chance for it being included in the core.

comment:16 Changed 5 years ago by aaugustin

Yes, this is #16332, and it's already implemented.

comment:17 Changed 5 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Note: See TracTickets for help on using tickets.
Back to Top