Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#16332 closed New feature (fixed)

add an i18n_url tag

Reported by: Florian Apolloner Owned by: nobody
Component: Template system Version: master
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


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)

i18n_urls.diff (5.9 KB) - added by Florian Apolloner 8 years ago.
i18n_urls.2.diff (5.9 KB) - added by Florian Apolloner 8 years ago.
typo fixes

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by Florian Apolloner

Attachment: i18n_urls.diff added

Changed 8 years ago by Florian Apolloner

Attachment: i18n_urls.2.diff added

typo fixes

comment:1 Changed 8 years ago by Łukasz Rekucki

Resolution: wontfix
Status: newclosed

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 Changed 8 years ago by Florian Apolloner

Resolution: wontfix
Status: closedreopened

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 Changed 8 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted

This tag complements the URLs i18n feature that was just added, and it looks useful.

The API is under discussion on the mailing list:

comment:4 Changed 8 years ago by Orne Brocaar

Cc: info@… 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 %}
Last edited 8 years ago by Orne Brocaar (previous) (diff)

comment:5 Changed 8 years ago by Jannis Leidel

Resolution: fixed
Status: reopenedclosed

In [16501]:

Fixed #16332 -- Added language template tag that switches the activate language for the enclosed template section, e.g. to allow translation of URLs as added in r16405. Many thanks to Florian Apolloner and Orne Brocaar.

comment:6 Changed 7 years ago by Jacob

milestone: 1.4

Milestone 1.4 deleted

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