我使用的是jinja 2.10和pybabel。当我的模板包含以下代码时(在trans块中有'%‘字符),pybabel-compile不会转换字符串。提取的字符串(在.po中)是正常的,但是在结果页面上它根本没有被翻译。
<h3 class="title">{% trans %}100% anonymity{% endtrans %}</h3>这段代码可以工作,但是转换语法看起来更好:
<h3 class="title">{{ _("100%% anonymity") }}</h3>此外,我不能麻烦我的翻译同事使用'%%‘而不是'%’。
发布于 2021-11-08 09:14:44
另一种方式:{% trans percent='%' %}100{{ percent }} anonymity{% endtrans %}
发布于 2018-09-04 20:00:53
我也坚持这一点,但我在Babel documentation中找到了解决方案:
##flask.ext.babel.gettext(string, **variables)##
##Translates a string with the current locale and passes in the given keyword arguments as mapping to a string formatting string.
gettext(u'Hello World!')
gettext(u'Hello %(name)s!', name='World')我把它翻译成这样的简单代码:
_('Hello %(name)s!', name='World%')我希望我能帮助你:D
https://stackoverflow.com/questions/50806712
复制相似问题