views:

19

answers:

2

I have some template code that looks like:

<input type='submit' value='{{ need.satisfied|yesno:"Resend this document now,Send this document now" }}' />

I'd like to be able to translate it but that appears to be difficult to accomplish.

http://code.djangoproject.com/ticket/3804 mentions

{{ _("Some String") }} 

which appears to work for literal strings, but when used like

{{ _(Variable) }} 

gives the error

Variables and attributes may not begin with underscores: '_'

So, how do you do it?

Oh yea, I tried doing:

'{% if blah %}{% trans "Resend..." %}{% else %}{% trans "Send..." %}{% endif %}'

which works, but look so ugly I don't want to. Surely with Django there is some more elegant way to do this.....

Seems like a |trans filter would be in order, but that was shot down as a non-issue with http://code.djangoproject.com/ticket/3804

A: 

have you tried using, blocktrans

{% blocktrans %}
    string to translate with {{ vars }}
{% endblocktrans %}
Ashok
Part of the problem comes from the need to be essentially {% spaceless %} because it is in the value attribute, the spaces are significant (and the newlines).The {% spaceless %} tag won't work because it just removes spaces between html tags, and therefore has not effect here.WolpH nailed this one
Mark0978
A: 

Judging by the example in the docs, it might be possible to do it like this:

<input type='submit' value='{{ need.satisfied|yesno:_("Resend this document now,Send this document now") }}' />

Source: http://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#other-tags

WoLpH
Thanks, that is exactly what I was looking for.
Mark0978