Jinja2 translation of links

我的未来我决定 提交于 2019-12-04 07:47:50

These should work:

{{ _('This is the') }} <a href="roadmap.html">{{ _('roadmap') }}</a>

{{ _('This is the %(roadmap)s', roadmap=('<a href="roadmap.html">%s</a>' % _('roadmap'))|safe) }} 

Also, if you use webapp2, you might want to replace href="roadmap.html" with e.g. href="{{ uri_for('roadmap') }}"

Here's a solution that will get you everything in a single translatable string. You usually don't want the link text ("roadmap") to be a separate translation item.

It works by extracting the opening and closing tag into variables. These must be marked as safe, since they contain HTML content that would otherwise be escaped.

{% trans link_start='<a href="roadmap.html">'|safe, link_end='</a>'|safe %}
This is the {{ link_start }} roadmap {{ link_end }}.
{% endtrans %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!