gpt4 book ai didi

python - Django 模板 : Translate include with variable

转载 作者:太空狗 更新时间:2023-10-30 02:45:22 25 4
gpt4 key购买 nike

我有一个模板,您可以在其中传递一个文本变量。我想将此模板包含到另一个模板中,但带有翻译文本,因为它是可变的。你如何才能做到这一点?

我想要这样的东西:

{% 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 %}

参见 the docs了解更多详情。

关于python - Django 模板 : Translate include with variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24831727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com