Opened 17 years ago

Closed 16 years ago

#7239 closed (wontfix)

Using the url tag with the blocktrans one

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

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 Larlet 17 years ago.
First naive implementation
patch_django_7239_documentation.20080617.diff (892 bytes ) - added by David Larlet 17 years ago.
Documentation of the patch
patch_django_7239.20080617.diff (7.5 KB ) - added by David Larlet 17 years ago.
All in one with regression tests
patch_django_7239.20080722.diff (10.9 KB ) - added by David Larlet 16 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 Larlet 16 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 by Jannis Leidel, 17 years ago

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 by David Larlet, 17 years ago

Status: newassigned

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 by Jannis Leidel, 17 years ago

Yay!

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

by David Larlet, 17 years ago

First naive implementation

comment:4 by David Larlet, 17 years ago

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 by David Larlet, 17 years ago

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

comment:6 by edgarsj, 17 years ago

Triage Stage: UnreviewedAccepted

by David Larlet, 17 years ago

Documentation of the patch

comment:7 by David Larlet, 17 years ago

Needs documentation: unset

Added documentation, review welcome given my poor english.

by David Larlet, 17 years ago

All in one with regression tests

comment:8 by David Larlet, 17 years ago

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.

by David Larlet, 16 years ago

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

comment:9 by Remco Wendt, 16 years ago

Triage Stage: AcceptedReady 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.

by David Larlet, 16 years ago

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

comment:10 by Malcolm Tredinnick, 16 years ago

Triage Stage: Ready for checkinAccepted

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

comment:12 by Viktor <viktor.nagy@…>, 16 years ago

Cc: viktor.nagy@… added

comment:13 by David Larlet, 16 years ago

Resolution: wontfix
Status: assignedclosed

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

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