如何更新现有的 messages.pot 文件? 比如我翻译了messages.pot文件:
....
#: forms.py:11
msgid "Nickname"
msgstr "Имя"
#: forms.py:18
msgid "Wrong email"
msgstr "Неправильный пароль"
....
如果我用选择器 gettext 标记新文本,例如:
flash(gettext('Login successful'))
然后运行:
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 ""
....
那么,如何更新现有的 messages.pot 文件,保存翻译后的字符串(“昵称”、“错误的电子邮件”)?
最佳答案
pot
文件不用于翻译,它只是列出所有要翻译的字符串,没有特定语言。
对于真正的翻译,使用 po
- 文本文件和 mo
- 带有翻译的二进制文件。该文件将为您需要的任何语言创建。查看我的文件结构:
translations/
translations/ru/
translations/ru/LC_MESSAGES/
translations/ru/LC_MESSAGES/messages.mo
translations/ru/LC_MESSAGES/messages.po
translations/messages.pot
获取所有要翻译的字符串:
pybabel extract -F babel.cfg -o messages.pot .
初始化 po
文件(第一次):
pybabel init -i messages.pot -d . -l ru
要更新存在的 po
文件:
pybabel update -i messages.pot -d .
将po
文件编译成mo
:
pybabel compile -f -d .
查看更多信息 documentation .
关于python - Flask-Babel 更新现有的 messages.pot 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18822396/