Opened 15 years ago

Closed 14 years ago

Last modified 13 years ago

#11585 closed New feature (fixed)

i18n in urls.py

Reported by: digi604 Owned by: Jannis Leidel
Component: Internationalization Version: dev
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

Description

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.

example:

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 Orne Brocaar 14 years ago.
Implementation for language-prefix and internationalization of URL patterns

Download all attachments as: .zip

Change History (18)

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Thejaswi Puthraya, 15 years ago

Component: UncategorizedInternationalization

comment:3 by Jannis Leidel, 15 years ago

milestone: 1.21.3

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

comment:4 by anonymous, 14 years ago

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:

/en/contact/

/de/kontakt/

/it/contatto/

comment:5 by Jannis Leidel, 14 years ago

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

comment:6 by Robert Lujo, 14 years ago

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 by Sam Bull, 14 years ago

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 by Jannis Leidel, 14 years ago

milestone: 1.3
Triage Stage: Design decision neededAccepted

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 by Julien Phalip, 14 years ago

Severity: Normal
Type: New feature

comment:11 by Orne Brocaar, 14 years ago

Easy pickings: unset
Owner: changed from nobody to Orne Brocaar
Status: newassigned
UI/UX: unset

comment:12 by Jonas Obrist, 14 years ago

Cc: jonas.obrist@… added

by Orne Brocaar, 14 years ago

Attachment: i18nurls.diff added

Implementation for language-prefix and internationalization of URL patterns

comment:13 by Orne Brocaar, 14 years ago

Cc: info@… added
Has patch: set
milestone: 1.4
Owner: changed from Orne Brocaar to Jannis Leidel
Status: assignednew

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 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

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 by Jakub Roztočil, 13 years ago

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 by Aymeric Augustin, 13 years ago

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

comment:17 by Jacob, 13 years ago

milestone: 1.4

Milestone 1.4 deleted

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