Merge pull request #434 from misuzu/flask-babel-3-compat

Fix compatibility with flask-babel v3
This commit is contained in:
Piero Toffanin 2023-04-27 13:16:12 -04:00 committed by GitHub
commit 90f1fa9b41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -1079,14 +1079,15 @@ def create_app(args):
return jsonify(lazy_swag(swag))
app.config["BABEL_TRANSLATION_DIRECTORIES"] = 'locales'
babel = Babel(app)
@babel.localeselector
def get_locale():
override_lang = request.headers.get('X-Override-Accept-Language')
if override_lang and override_lang in get_available_locale_codes():
return override_lang
return session.get('preferred_lang', request.accept_languages.best_match(get_available_locale_codes()))
babel = Babel(app, locale_selector=get_locale)
app.jinja_env.globals.update(_e=gettext_escaped, _h=gettext_html)
# Call factory function to create our blueprint

View file

@ -3,7 +3,7 @@ Flask==2.2.2
flask-swagger==0.2.14
flask-swagger-ui==4.11.1
Flask-Limiter==2.6.3
Flask-Babel==2.0.0
Flask-Babel==3.1.0
Flask-Session==0.4.0
waitress==2.1.2
expiringdict==1.2.2