Code

Opened 6 years ago

Closed 6 years ago

#7239 closed (wontfix)

Using the url tag with the blocktrans one

Reported by: david Owned by: david
Component: Template system Version: master
Severity: Keywords:
Cc: viktor.nagy@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

For the moment, you can't use blocktrans with the url tag:

{% blocktrans %}
foo {% url bar %} baz.
{% endblocktrans %}

It seems that it had already been discussed: http://groups.google.fr/group/django-developers/browse_thread/thread/e8b6b99973b10a17
but I can't find a ticket about that. If someone can post the final syntax (We're pretty close to having a good syntax), I can write the patch.

Attachments (5)

patch_django_7239.20080530.diff (1.9 KB) - added by david 6 years ago.
First naive implementation
patch_django_7239_documentation.20080617.diff (892 bytes) - added by david 6 years ago.
Documentation of the patch
patch_django_7239.20080617.diff (7.5 KB) - added by david 6 years ago.
All in one with regression tests
patch_django_7239.20080722.diff (10.9 KB) - added by david 6 years ago.
New patch against r8053 with additional tests for combined arguments in url tag
patch_django_7239.20080809.diff (11.4 KB) - added by david 6 years ago.
New patch against r8255 which handle decision in r8211 and add tests for this situation

Download all attachments as: .zip

Change History (18)

comment:1 Changed 6 years ago by jezdez

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Hi David, the thread is here: http://groups.google.fr/group/django-developers/browse_thread/thread/4c7b2ce86bcd990e and has a fairly good syntax at the end, I think.

comment:2 Changed 6 years ago by david

  • Status changed from new to assigned

Thanks jezdez for the link, for the record, here is a quote from the final example:

So this would make the syntax like this :

{% blocktrans with message.created|date as date and user.married|year as married_since and user.name as username %} 
    Received on {{ date }} 
    from 
    {% as link_open %}<a href="{% url userlink user.id %}">{% endas %} 
         {{ username }} (married since {{ married_since }}) 
    {% as link_close %}<a/>{% endas %} 
{% endblocktrans %}

Then the string to translated would be :

"Received on %(date)s from %(link_open)s %(username)s (married since %(married_since)s) %(link_close)%" 

I'm not fond of all those tags but I'll try to write a patch.

comment:3 Changed 6 years ago by jezdez

Yay!

As for the "as" subtag you may want to have a look at http://www.djangosnippets.org/snippets/545/.

Changed 6 years ago by david

First naive implementation

comment:4 Changed 6 years ago by david

Eventually I implemented:

{% blocktrans with message.created|date as date and user.married|year as married_since and user.name as username url userlink user.id as user_url %} 
    Received on {{ date }} 
    from 
    <a href="{{ user_url }}">{{ username }} (married since {{ married_since }})<a/>
{% endblocktrans %}

It seems a lot more readable to me and it's consistent with the existing "count" alternative. I reuse URLNode from the url tag.

The translated result is:

"Received on %(date)s from <a href=\"%(user_url)s\">%(username)s (married since %(married_since)s)</a>"

Any thoughts? (I'll add tests too but I need to be sure that this syntax is accepted first).

comment:5 Changed 6 years ago by david

  • Cc malcolm removed
  • Has patch set
  • Needs documentation set
  • Needs tests set

comment:6 Changed 6 years ago by edgarsj

  • Triage Stage changed from Unreviewed to Accepted

Changed 6 years ago by david

Documentation of the patch

comment:7 Changed 6 years ago by david

  • Needs documentation unset

Added documentation, review welcome given my poor english.

Changed 6 years ago by david

All in one with regression tests

comment:8 Changed 6 years ago by david

  • Needs tests unset

Added tests.

BTW, I found a bug in tests.regressiontests.templates.tests with url02, there is a space between client.id, and action="update" and this option is not mentioned in documentation (it breaks my code if it's intentional):

'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),

I suggest to remove it.

Changed 6 years ago by david

New patch against r8053 with additional tests for combined arguments in url tag

comment:9 Changed 6 years ago by shanx

  • Triage Stage changed from Accepted to Ready for checkin

Excellent, unittest in the new patch handles all the other cases of using url in blocktrans. I've tested it here against revision 8053 of trunk with Django's unittest framework and functionally using a local testproject.

Marking ready for checkin so a core dev can have a look at it.

Changed 6 years ago by david

New patch against r8255 which handle decision in r8211 and add tests for this situation

comment:10 Changed 6 years ago by mtredinnick

  • Triage Stage changed from Ready for checkin to Accepted

"ready for checkin" means just that, not "needs a higher-level review", so moving back to the right state.

comment:12 Changed 6 years ago by Viktor <viktor.nagy@…>

  • Cc viktor.nagy@… added

comment:13 Changed 6 years ago by david

  • Resolution set to wontfix
  • Status changed from assigned to closed

Close as wontfix given the new "as" keyword in url tag. See this thread for details:
http://groups.google.com/group/django-developers/browse_thread/thread/5e9d28a878091346/454017eb2277b59f

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.