Closed vincentwhales closed 6 years ago
I have been spending an entire afternoon trying to figure out why I am able to see the translation for Flask-Admin but not my own.
These are the commands that I am using:
- `pybabel extract -F translations/babel.cfg -o translations/messages.pot .` - (Run this only for the first time) `pybabel init -i translations/messages.pot -d translations/translations -l zh` - Edit the messages.po file - `pybabel compile -d translations/`
This is what I have so far in views:
from flask_babelex import Babel ... babel = Babel(app) @babel.localeselector def get_locale(): if request.args.get('lang'): session['lang'] = request.args.get('lang') return session.get('lang', 'en')
I am trying to translate this jinja snippet:
<li class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ _('Language') }}<span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="?lang=en">{{ _('English') }}</a></li> <li><a href="?lang=zh_CN">{{ _('Chinese') }}</a></li> </ul> </li>
This is my translation folder:
translations/ ├── babel.cfg ├── messages.pot └── zh └── LC_MESSAGES ├── messages.mo └── messages.po
My messages.pot:
#: portal/templates/admin/base.html:91 msgid "Language" msgstr "" #: portal/templates/admin/base.html:93 msgid "English" msgstr "" #: portal/templates/admin/base.html:94 msgid "Chinese" msgstr ""
and my messages.po:
#: portal/templates/admin/base.html:93 msgid "English" msgstr "英文" #: portal/templates/admin/base.html:94 msgid "Chinese" msgstr "中文"
And I manually verified that messages.mo is updated correctly (I viewed it in vim).
The strangest thing is, when I added ?lang=zh_CN to my homepage, I am seeing this:
?lang=zh_CN
From what I have provided so far:
This is not a Flask admin issue. I guess you forgot to create a babel.cfg file. Please have a look on flask babelex documentation.
I have been spending an entire afternoon trying to figure out why I am able to see the translation for Flask-Admin but not my own.
These are the commands that I am using:
This is what I have so far in views:
I am trying to translate this jinja snippet:
This is my translation folder:
My messages.pot:
and my messages.po:
And I manually verified that messages.mo is updated correctly (I viewed it in vim).
The strangest thing is, when I added
?lang=zh_CN
to my homepage, I am seeing this:From what I have provided so far:
Does anyone know what my own texts are not being translated?