Jinja2翻译链接 [英] Jinja2 translation of links
本文介绍了Jinja2翻译链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是< p>< p> ; a href =roadmap.html>路线图< / a>
荷兰语翻译结果如下:
Dit是de< a href =roadmap.html>计划< / a>
这条Jinja2线让我到达 - 几乎 -
{{_('这是%(roadmap)s。',roadmap ='< a href =roadmap.html>路线图< / a>'|安全)}}
不幸的是,'roadmap'这个词没有被翻译。
Jinja2完成此操作的方式是什么?将路线图1和路线图2中的链接分开?我希望有更聪明的东西。
解决方案
这些应该可以工作:
{{_('这是')}}< a href =roadmap.html> {{_('roadmap')}}< / a>
{{_('这是%(roadmap)s',roadmap =('< a href =roadmap.html>%s< / a>'%_('如果你使用webapp2,你可能想要替换href =roadmap.html与例如 href ={{uri_for('roadmap')}}
From a Jinja2 template, this is the rendered line I'm after (in English):
This is the <a href="roadmap.html">roadmap</a>
Translated in Dutch should result in:
Dit is de <a href="roadmap.html">planning</a>
This Jinja2 line gets me there -almost-
{{ _('This is the %(roadmap)s.', roadmap='<a href="roadmap.html">roadmap</a>'|safe) }}
Unfortunately, the word 'roadmap' is not translated.
What would be the Jinja2 way of accomplishing this? Splitting the link in roadmap1 and roadmap2? I hope for something more clever.
解决方案 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') }}"
这篇关于Jinja2翻译链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文