Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#16332 closed New feature (fixed)

add an i18n_url tag

Reported by: apollo13 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 apollo13 4 years ago.
i18n_urls.2.diff (5.9 KB) - added by apollo13 4 years ago.
typo fixes

Download all attachments as: .zip

Change History (8)

Changed 4 years ago by apollo13

Changed 4 years ago by apollo13

typo fixes

comment:1 Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to 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 Changed 4 years ago by apollo13

  • Resolution wontfix deleted
  • Status changed from closed to 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 Changed 4 years ago by aaugustin

  • Triage Stage changed from Unreviewed to 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:

comment:4 Changed 4 years ago by 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 4 years ago by brocaar (previous) (diff)

comment:5 Changed 4 years ago by jezdez

  • Resolution set to fixed
  • Status changed from reopened to closed

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 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

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