Opened 16 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)
Change History (18)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Status: | new → 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 by , 16 years ago
Yay!
As for the "as" subtag you may want to have a look at http://www.djangosnippets.org/snippets/545/.
comment:4 by , 16 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 , 16 years ago
Cc: | removed |
---|---|
Has patch: | set |
Needs documentation: | set |
Needs tests: | set |
comment:6 by , 16 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 16 years ago
Attachment: | patch_django_7239_documentation.20080617.diff added |
---|
Documentation of the patch
comment:7 by , 16 years ago
Needs documentation: | unset |
---|
Added documentation, review welcome given my poor english.
by , 16 years ago
Attachment: | patch_django_7239.20080617.diff added |
---|
All in one with regression tests
comment:8 by , 16 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 , 16 years ago
Attachment: | patch_django_7239.20080722.diff added |
---|
New patch against r8053 with additional tests for combined arguments in url tag
comment:9 by , 16 years ago
Triage Stage: | Accepted → 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.
by , 16 years ago
Attachment: | patch_django_7239.20080809.diff added |
---|
comment:10 by , 16 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
"ready for checkin" means just that, not "needs a higher-level review", so moving back to the right state.
comment:11 by , 16 years ago
Here is the latest discussion about this bug: http://groups.google.com/group/django-developers/browse_thread/thread/3df6010d5212a8ce/8576875374900a5b
comment:12 by , 16 years ago
Cc: | added |
---|
comment:13 by , 16 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → 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
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.