flask-babelex
flask-babelex copied to clipboard
Not working with Flask-Babel?
I am using two extensions:
Flask-User (which uses Flask-Babel), and Flask-Admin (which uses Flask-Babelex)
When I try to get i18n working for my application, I am seeing cryptic errors such as:
Traceback (most recent call last):
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/views.py", line 293, in logout
flash(_('You have signed out successfully.'), 'success')
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/translations.py", line 51, in gettext
translations = get_translations()
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_user/translations.py", line 47, in get_translations
return ctx.flask_user_translations.merge(babel.get_translations())
File "/Users/vng/.virtualenvs/portal/lib/python2.7/site-packages/flask_babel/__init__.py", line 224, in get_translations
for dirname in babel.translation_directories:
AttributeError: 'Babel' object has no attribute 'translation_directories'
Is there a guide to integrating both extensions at the same time?
Good question. Does anyone happen to know what is the overall situation of Flask-Babel vs Flask-BabelEx? Planning upgrade Flask app to all latest. Using Flask-Babel now, but seems like some Flask libraries qill require BabelEx (and as pointed above those are not compatible), plus force_locale missing from BabelEx. OTOH, BabelEx is not being actively developed (last commit almost a year ago), or is it?. I was even thinking to make some kind of BabelEx with force_locale, but not quite sure whether there is any perspective.
PS. You can probably get away by importing gettext from Flask-BabelEx instead of Flask-Babel, but I unfortunately can't.