hello world
全程请注意文件路径: -d 后面的,flask
https://blog.csdn.net/lichengtongxiazai/article/details/22270561
https://blog.csdn.net/weixin_42126327/article/details/81901045?utm_source=blogxgwz1
1.使用以下命令来将所有文本提取到* .pot *文件:
pybabel extract -F babel.cfg -o messages.pot . 提取文件
(pybabel extract -F babel.cfg -k _l -o messages.pot . 考虑到lazygettext的情况)
注意结尾的点“.”,这个点表示当前目录,
2.pybabel init -i messages.pot -d translations -l zh_Hans_CN
(pybabel init -i messages.pot -d app/translations -l es)
这句命令会在 hello 文件夹中生成一个 translations 文件夹,要确保 flask 能找到翻译内容,
translations文件夹要和 templates 文件夹在同一个目录中。接下来我们就可以进行翻译了,
修改 translations/zh_Hans_CN/LC_MESSAGES/messages.po 文件,将其中的内容翻译过来
PO文件的翻译其实可以用专门的工具来编辑,比如Poedit,不过小文件直接手译就可以了。
3.pybabel compile -d translations
(pybabel compile -d app/translations)
如果上述命令无法生成 messages.mo 文件,那你需要将 message.po 中的#,fuzzy删除。
4.更新翻译
有时我们需要对程序和模板做修改,翻译也要随之更新。更新后需要用前面的命令重新生成 messages.pot 文件,
然后使用下面的命令将更新的内容 merge 到原来的翻译中:
pybabel extract -f babel.cfg -k _l -o messages.pot .
pybabel update -i messages.pot -d app/translations(pybabel update -i messages.pot -d translations)
https://blog.csdn.net/weixin_42126327/article/details/81901045?utm_source=blogxgwz1