#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)
Change History (18)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:2 by , 15 years ago
Component: | Uncategorized → Internationalization |
---|
comment:3 by , 15 years ago
milestone: | 1.2 → 1.3 |
---|
comment:4 by , 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 , 14 years ago
This is somewhat related to #9333, which proposes adding a note about django-localeurl to the documentation.
comment:6 by , 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:7 by , 14 years ago
I think this is an intriguing idea: http://www.pocketuniverse.ca/archive/2010/november/30/urls-multi-lingual-sites-solution/
Code here: https://github.com/trapeze/transurlvania
comment:8 by , 14 years ago
Cc: | 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 , 14 years ago
milestone: | 1.3 |
---|---|
Triage Stage: | Design decision needed → 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 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:11 by , 13 years ago
Easy pickings: | unset |
---|---|
Owner: | changed from | to
Status: | new → assigned |
UI/UX: | unset |
comment:12 by , 13 years ago
Cc: | added |
---|
by , 13 years ago
Attachment: | i18nurls.diff added |
---|
Implementation for language-prefix and internationalization of URL patterns
comment:13 by , 13 years ago
Cc: | added |
---|---|
Has patch: | set |
milestone: | → 1.4 |
Owner: | changed from | to
Status: | assigned → 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:15 by , 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.
Moving to 1.3 since this is certainly a new feature and we are in bugfix only mode.