如何在Django中翻译过滤器的输出

boa*_*der 5 django translation django-templates internationalization

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

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

我希望能够翻译它,但似乎很难完成.

http://code.djangoproject.com/ticket/3804提及

{{ _("Some String") }} 
Run Code Online (Sandbox Code Playgroud)

这似乎适用于文字字符串,但使用时喜欢

{{ _(Variable) }} 
Run Code Online (Sandbox Code Playgroud)

给出了错误

Variables and attributes may not begin with underscores: '_'
Run Code Online (Sandbox Code Playgroud)

你是怎么做到的?

哦,是的,我尝试过:

'{% if blah %}{% trans "Resend..." %}{% else %}{% trans "Send..." %}{% endif %}'
Run Code Online (Sandbox Code Playgroud)

这是有效的,但看起来很丑,我不想.肯定有Django有一些更优雅的方式来做到这一点.....

看起来像一个| trans过滤器将是有序的,但这被拍成了一个非问题的http://code.djangoproject.com/ticket/3804

Wol*_*lph 13

从文档中的示例来看,有可能这样做:

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

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