如何在Django中转换过滤器的输出

如何在Django中转换过滤器的输出,django,django-templates,internationalization,translation,Django,Django Templates,Internationalization,Translation,我有一些模板代码如下所示: <input type='submit' value='{{ need.satisfied|yesno:"Resend this document now,Send this document now" }}' /> 它似乎适用于文本字符串,但在类似 {{ _(Variable) }} 给出了错误 Variables and attributes may not begin with underscores: '_' 那么,你是怎么做到的 哦,是的

我有一些模板代码如下所示:

<input type='submit' value='{{ need.satisfied|yesno:"Resend this document now,Send this document now" }}' />
它似乎适用于文本字符串,但在类似

{{ _(Variable) }} 
给出了错误

Variables and attributes may not begin with underscores: '_'
那么,你是怎么做到的

哦,是的,我试着做:

'{% if blah %}{% trans "Resend..." %}{% else %}{% trans "Send..." %}{% endif %}'
这很管用,但看起来很难看,我不想。当然,对于Django,有一些更优雅的方法可以做到这一点

看起来一个| trans过滤器应该是合适的,但这被认为是一个非问题,你试过使用吗


根据文档中的示例判断,可以这样做:

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


来源:

谢谢,这正是我想要的。部分问题来自于本质上需要{%spaceless%},因为它在value属性中,空格是重要的(以及换行符)。{%spaceless%}标记将不起作用,因为它只是删除html标记之间的空格,因此在这里无效。沃尔夫搞定了这个
{% blocktrans %}
    string to translate with {{ vars }}
{% endblocktrans %}
<input type='submit' value='{{ need.satisfied|yesno:_("Resend this document now,Send this document now") }}' />