How to convert filter output to Django

I have a template code that looks like this:

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

I would like to be able to translate it, but it is difficult to accomplish.

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

{{ _("Some String") }} 

which seems to work for letter strings, but when used as

{{ _(Variable) }} 

gives an error

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

So how do you do this?

Oh yes, I tried to do:

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

which works but look so ugly that I don’t want. Of course, with Django there is an even more elegant way to do this .....

It looks like the filter should be fine, but it was knocked down as a problem without http://code.djangoproject.com/ticket/3804

+5
2

, :

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

: https://docs.djangoproject.com/en/1.11/topics/i18n/translation/#string-literals-passed-to-tags-and-filters

+11

blocktrans

{% blocktrans %}
    string to translate with {{ vars }}
{% endblocktrans %}
+1

All Articles