Trevor Caira
unread,Dec 24, 2007, 12:17:15 AM12/24/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django developers, doct...@gmail.com
Since assignment of variables is illegal in the template syntax, and
{% blocktrans %} cannot contain other tags (notably {% url %}), there
is a problem for marking strings as translatable which contain links
in them in django templates.
Sometimes you can get around it with something like {% blocktrans with
post.get_absolute_url as posturl %}See the <a
href="{{ posturl }}">next post</a>{% endblocktrans %} (sorry for the
contrived example)--but in the general case, you need a different
solution.
My perception is that the general workaround is to do the url
resolution with urlresolvers.reverse in the view and pass the url in
as template context. Of course, this is a disgusting hack, and I'd
like to come up with a workaround for this.
It appears to me that the only clean resolution will involve adding
new or changing existing template tags. Naturally the first
candidates to look at are {% blocktrans %} and {% url %}. Blocktrans's
syntax is a little strained as it is; so I think it makes sense to
augment {% url %} instead. One possible solution is:
{% blocktrans %}Baz foo <a href="{% url bar arg1,arg2 as barurl
%}">bar</a> bat.{% endblocktrans %}
which would generated the translatable string:
"Baz foo <a href="%(barurl)s">bar</a> bat."
What are your thoughts on this proposed solution?
-- Trevor