对不起,我是烧瓶巴别塔的新手,也是烧瓶的新手! 我的烧瓶代码:
test.py
app = Flask(__name__)
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
babel = Babel(app)
@app.route('/', methods=['GET'])
def hello_world():
message = _(u'测试 页面')
return render_template('index.html', message=message)
索引.html
<h1>{{ _("测试") }}</h1>
<h2>{{ _("消息:%(m)s", m=message) }}</h2>
消息宝
#: learnflask.py:23
msgid "测试 页面"
msgstr "test page"
#: templates/index.html:8
msgid "测试"
msgstr "Test"
#: templates/index.html:9
#, python-format
msgid "消息:%(m)s"
msgstr "message: %(m)s"
结果:
测试
消息:测试 页面
第一个字符串翻译正确,但第二个字符串翻译不正确。我想知道如何让它工作。请帮忙。谢谢!
好的。我找到了答案。这几乎就像您在更新 .po 文件时应该删除 .mo 文件一样。 我删除message.mo
,并使用python compile -d translations
生成新的message.mo
,然后它工作正常!