在Jinja2模板中,这是我想要的呈现行(英文):
This is the <a href="roadmap.html">roadmap</a>
翻译成荷兰语的结果应该是:
Dit is de <a href="roadmap.html">planning</a>
这条Jinja2线路把我带到了那里-几乎-
{{ _('This is the %(roadmap)s.', roadmap='<a href="roadmap.html">roadmap</a>'|safe) }}
不幸的是,“路线图”这个词没有被翻译。
Jinja2实现这一目标的方式是什么?在roadmap1和roadmap2中拆分链接?我希望能有更聪明的东西。
发布于 2012-03-23 18:36:57
这些应该是有效的:
{{ _('This is the') }} <a href="roadmap.html">{{ _('roadmap') }}</a>
{{ _('This is the %(roadmap)s', roadmap=('<a href="roadmap.html">%s</a>' % _('roadmap'))|safe) }}
此外,如果您使用webapp2,则可能需要将href="roadmap.html“替换为例如href="{{ uri_for('roadmap') }}"
发布于 2018-06-27 07:11:07
这里有一个解决方案,可以让你在一个可翻译的字符串中得到所有的东西。您通常不希望链接文本(“路线图”)成为单独的翻译项目。
它的工作原理是将开始和结束标记提取到变量中。它们必须标记为safe
,因为它们包含否则将被转义的HTML内容。
{% trans link_start='<a href="roadmap.html">'|safe, link_end='</a>'|safe %}
This is the {{ link_start }} roadmap {{ link_end }}.
{% endtrans %}
https://stackoverflow.com/questions/9835727
复制相似问题