python - Flask Babel doesn't work -
i use flask babel i18n flask admin project. cannot make works, simple template. here codes, initialize babel first,
app=flask(__name__,template_folder='templates') app.config.from_object('config') csrf=csrfprotect(app) bcrypt=bcrypt(app) db=sqlalchemy(app) babel=babel(app) @babel.localeselector def get_locale(): return 'zh_hans_cn'
add construct admin page , add i18n, tries lazy_gettext().not work.
# create admin admin = admin.admin(app, 'iinvest:', index_view=myadminindexview(), base_template='my_master.html') # add view admin.add_view(usermanageview(user, db.session, gettext(u'user management')))
use babel i18n , add translations,
os.system(pybabel + ' extract -f babel.cfg -k lazy_gettext -o messages.pot iinvest/') os.system(pybabel + ' init -i messages.pot -d translations -l zh_hans_cn') os.unlink('messages.pot')
it finds texts , add translations manually, compile it,
os.system(pybabel + ' compile -f -d translations')
restart server , check page, nothing translated. tried other languages, none of them works. what's possible reason? here full code https://github.com/xiaokunhou/flaskproject
i find wrong. translations folder in wrong place. should under iinvest(which app in other cases)..
pybabel extract -f babel.cfg -k lazy_gettext -o messages.pot iinvest/ pybabel init -i messages.pot -d iinvest/translations -l zh_hans_cn pybabel compile -f -d iinvest/translations
Comments
Post a Comment