gettext – Flask-Babel如何在Jinja模板文件中使用翻译
发布时间:2020-12-05 07:01:18 所属栏目:Python 来源:互联网
导读:在我的Flask应用程序中,在main.py文件中,我定义了: from flaskext.babel import gettext....def somefun(): return render_template(some.html, messages=messages) 在模板文件some.html中,我用过: input type=text name=keywords
在我的Flask应用程序中,在main.py文件中,我定义了: from flaskext.babel import gettext .... def somefun(): return render_template('some.html',messages=messages) 在模板文件some.html中,我用过: <input type='text' name='keywords' value='{{ keywords|default('') }}' placeholder='{{ gettext('Search...') }}' /> 这给出错误: <input type='text' name='keywords' value='{{ keywords|default('') }}' placeholder='{{ gettext('Search...') }}' /> UndefinedError: 'gettext' is undefined 如何导入这个功能,让模板使用? 解决方法不幸的是,这根本没有记载,但Flask-Babel透明地使用了 Jinja2’s i18n extension.这意味着默认情况下,表达式的以下函数可用:_gettext,_ngettext和_.还有可能使用模板标签: {% trans %}foo{% endtrans%} {% trans num %} There is {{ num }} object. {% pluralize %} There are {{ num }} objects. {% endtrans %} 而bug report about missing docs正在等待补丁;) (编辑:甘南站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读