You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incompatible with multiple apps with different translations #107
Flask-Babel stores an app instance in self.app, which will be set in init_app() regardless. This means that using the same Babel instance with multiple apps (each app running babel_instance.init_app(app) doesn't work as expected: Only the translations from the last app configured will be used.
Hi, I am trying out version 3.0 that was just released and am hitting the deprecation in __init__.py of a Flask app of:
@babel.localeselector
def get_locale():
....
What is the recomended approach to use instead of above, to be compatible with Flask-Babel v3.0? Thanks!
EDIT: As best I can tell, before the upgrade with the old decorator, this get_locale method was getting called per-request. After the upgrade (dropping the decorator line), the method is no longer called and my app pages are no longer translated.
EDIT2: Sorry, my mistake. I found the answer digging into the diffs made to the documentation above. Leaving the answer for any others who hit this on upgrade to v3.0.
Activity
davidism commentedon Jul 27, 2016
For reference, Flask-SQLAlchemy implements a
get_appmethod and uses that anywhere an app is required.timothyqiu commentedon Oct 15, 2016
The same goes for
localeselectorandtimezoneselector. They are bound to the Babel instance, so can't be configured separately for different apps 😢FYI, Flask-SQLAlchemy and Flask-Mail store app specific states in
app.extensions['NAME'].Start moving everything off of the Babel() and app instances and stor…
Tests for #107.
Update more documentation for #107.
guydavis commentedon Jan 16, 2023
Hi, I am trying out version 3.0 that was just released and am hitting the deprecation in
__init__.pyof a Flask app of:What is the recomended approach to use instead of above, to be compatible with Flask-Babel v3.0? Thanks!
EDIT: As best I can tell, before the upgrade with the old decorator, this
get_localemethod was getting called per-request. After the upgrade (dropping the decorator line), the method is no longer called and my app pages are no longer translated.EDIT2: Sorry, my mistake. I found the answer digging into the diffs made to the documentation above. Leaving the answer for any others who hit this on upgrade to v3.0.
My old code:
Changed to work with Flask-Babel v3.0:
application: Update Babel syntax for new v3 format