Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#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)

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

Download all attachments as: .zip

Change History (8)

by Florian Apolloner, 13 years ago

Attachment: i18n_urls.diff added

by Florian Apolloner, 13 years ago

Attachment: i18n_urls.2.diff added

typo fixes

comment:1 by Łukasz Rekucki, 13 years ago

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 by Florian Apolloner, 13 years ago

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

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: https://groups.google.com/group/django-developers/browse_thread/thread/64d33b99e5ef13b0

comment:4 by Orne Brocaar, 13 years ago

Cc: info@… added

What about not implementing this as a url tag but as a translation-override tag? Then it is not only possible 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 %}
Version 0, edited 13 years ago by Orne Brocaar (next)

comment:5 by Jannis Leidel, 13 years ago

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

milestone: 1.4

Milestone 1.4 deleted

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