From 0f8952fd10ff09eaadb66516a8ed262aacaade39 Mon Sep 17 00:00:00 2001 From: misuzu Date: Thu, 27 Apr 2023 19:21:04 +0300 Subject: [PATCH] Fix compatibility with flask-babel v3+ Babel.locale_selector was removed in 3.0.0 --- libretranslate/app.py | 5 +++-- requirements.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index ea4c0b6..e9f1d13 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -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 diff --git a/requirements.txt b/requirements.txt index a725f4c..2948d5e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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