Skip to content
Advertisement

Flask-Babel do not translate anything in a web project

Description of my usage:

This is my project structure(basically base on Flask Web Development):

JavaScript

Configuration in /babel.cfg and /app/__init__.py

babel.cfg:

JavaScript

app/__init__.py:

JavaScript

Then I follow the Flask-Babel document

Run $ pybabel extract -F babel.cfg -o messages.pot .

Run $ pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .

They do have found all the gettexts and lazy_gettexts.

Run $ pybabel init -i messages.pot -d translations -l zh_CN

This generate a /translations/zh_CN/LC_MESSAGES/messages.po for me. And I fixed some translations in it.(including delete the # .fuzzy)

Finally I run $ pybabel compile -d translations. This generate the /tranlations/zh_CN/LC_MESSAGES/messages.mo successfully.

But nothing has been translated……And I really don’t know how to fix this bug.

I was really screwed up with this for several days.

For more information,I put this project on Github.

Advertisement

Answer

because the actual locale name parsed by babel is “zh_Hans_CN”, name your translation directory to be “zh_Hans_CN”, and it will be found.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement