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
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: https://docs.djangoproject.com/en/1.11/topics/i18n/translation/#string-literals-passed-to-tags-and-filters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With