我有一个模板,可以传递文本变量。我想将此模板包含到另一个模板中,但使用翻译后的文本作为其变量。如何实现这一点? 我希望像这样: {% include "a_dir/stuff.html" with text={% trans "Load more promotions" %} %} 我考虑编写自己的模板标签来执行 ugettext,但是当创建 .po 文件时,文本变量将不会被自动获取。我不想在 view 中完成这项工作,因为我们所有的翻译都发生在模板中。
您可以使用as语法将翻译后的字符串放入变量中。例如: {% trans "Load more promotions" as promotions %} {% include "a_dir/stuff.html" with text=promotions %} 请参阅文档以获取更多详细信息。