Django

Code

Ticket #7239 (assigned)

Opened 2 months ago

Last modified 1 month ago

Using the url tag with the blocktrans one

Reported by: david Assigned to: david (accepted)
Milestone: Component: Template system
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

patch_django_7239.20080530.diff (1.9 kB) - added by david on 05/29/08 18:43:16.
First naive implementation
patch_django_7239_documentation.20080617.diff (0.9 kB) - added by david on 06/16/08 18:37:56.
Documentation of the patch
patch_django_7239.20080617.diff (7.5 kB) - added by david on 06/16/08 19:21:53.
All in one with regression tests

Change History

05/26/08 06:58:15 changed by jezdez

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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.

05/26/08 07:09:42 changed 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.

05/26/08 07:33:58 changed by jezdez

Yay!

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

05/29/08 18:43:16 changed by david

  • attachment patch_django_7239.20080530.diff added.

First naive implementation

05/29/08 18:50:34 changed 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).

06/12/08 15:37:51 changed by david

  • cc deleted.
  • needs_docs set to 1.
  • has_patch set to 1.
  • needs_tests set to 1.

06/12/08 15:45:54 changed by edgarsj

  • stage changed from Unreviewed to Accepted.

06/16/08 18:37:56 changed by david

  • attachment patch_django_7239_documentation.20080617.diff added.

Documentation of the patch

06/16/08 18:39:15 changed by david

  • needs_docs deleted.

Added documentation, review welcome given my poor english.

06/16/08 19:21:53 changed by david

  • attachment patch_django_7239.20080617.diff added.

All in one with regression tests

06/16/08 19:28:07 changed by david

  • needs_tests deleted.

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.


Add/Change #7239 (Using the url tag with the blocktrans one)




Change Properties
Action