我使用 Flask-Babel 进行翻译。使用函数来确定语言环境:
LANGUAGES = ['en', 'ru']
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(LANGUAGES)
Run Code Online (Sandbox Code Playgroud)
例如,如何根据语言环境为每个人的 url 添加 url-prefix?
ru/quotes
Run Code Online (Sandbox Code Playgroud)
或者
en/quotes
Run Code Online (Sandbox Code Playgroud)
我想设置链接以在模板中选择语言。我怎样才能做到这一点?
如何更新现有的messages.pot文件?例如,我已经翻译了messages.pot文件:
....
#: forms.py:11
msgid "Nickname"
msgstr "???"
#: forms.py:18
msgid "Wrong email"
msgstr "???????????? ??????"
....
Run Code Online (Sandbox Code Playgroud)
如果我用选择器gettext标记新文本,例如:
flash(gettext('Login successful'))
Run Code Online (Sandbox Code Playgroud)
并运行:
pybabel extract -F babel.cfg -o messages.pot
我将收到一个新的messages.po文件:
....
#: forms.py:11
msgid "Nickname"
msgstr ""
#: forms.py:18
msgid "Wrong email"
msgstr ""
#: models.py:783
msgid "Login successful"
msgstr ""
....
Run Code Online (Sandbox Code Playgroud)
那么,如何更新现有的messages.pot文件,保存已翻译的字符串("昵称","错误的电子邮件")?