#16332 closed New feature (fixed)
add an i18n_url tag
Reported by: | Florian Apolloner | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | i18n, url |
Cc: | info@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I propose adding an url tag which can take care of linking to other language; syntax would be:
{% i18n_url viewname lang k1=v1, k2=v2 %}
where viewname and k* behave like the future url tag and lang is either a context var containing a the lang-code or a literal string 'de' etc…
One thing about the attached patch: the i18n_url tag parsing is pretty much a copy of future_url, I am open to suggestions on making that one nicer…
One thing I also tried and failed miserably: I would like to have a tag like {% link_to some_url some_other_language %} which would take the url (could be the current url) and resolve it using the urlresolvers and then reverse using some_other_language. Sadly this fails due to resolver.resolve returning extra_context as part of kwargs which are passed to the function.
P.S.: patch should be importable via hg import
Attachments (2)
Change History (8)
by , 13 years ago
Attachment: | i18n_urls.diff added |
---|
by , 13 years ago
Attachment: | i18n_urls.2.diff added |
---|
comment:1 by , 13 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I'm not sure translating URLs is a good idea. How do you match the translated URL to the view ? Do you have all patterns in URLconf for every language. Do you sync them if the translation changes? How do you determine what is the active language for that URL ? IMHO, you need some extra indication, 'cause translations aren't unique to the language. You might want to take this to django-developers for discussion.
comment:2 by , 13 years ago
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
Uhm this ticket isn't about translating URLs, it's just about reversing them in the template. Translating them is already possible if you look at the trunk. Reopening…
comment:3 by , 13 years ago
Triage Stage: | Unreviewed → Accepted |
---|
This tag complements the URLs i18n feature that was just added, and it looks useful.
The API is under discussion on the mailing list: https://groups.google.com/group/django-developers/browse_thread/thread/64d33b99e5ef13b0
comment:4 by , 13 years ago
Cc: | added |
---|
What about not implementing this as a url tag but as a translation-override tag? Then it is not only possible to specify the language to use for your URL translation, but as well for other translatable content. Example:
{% transoverride language_code %} {% trans "Register account" %}: {% url account:register %} {% endtransoverride %}
typo fixes