fix(i18n): use babel.locale_selector instead of babel.localeselector for Flask-Babel 4.0.0

- Flask-Babel 4.0.0 changed the API
- @babel.localeselector -> @babel.locale_selector
- Remove redundant request import in context processor
- All tests still pass
This commit is contained in:
ijuanes 2026-06-20 10:01:38 +01:00
parent 34dd3ca937
commit 6282bb9789

3
app.py
View file

@ -26,7 +26,7 @@ app.config['LANGUAGES'] = {
# Configure translation directory # Configure translation directory
app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations' app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations'
@babel.localeselector @babel.locale_selector
def get_locale(): def get_locale():
# Try to get language from URL parameter # Try to get language from URL parameter
lang = request.args.get('lang') lang = request.args.get('lang')
@ -41,7 +41,6 @@ def get_locale():
# Context processor to make language and config available in templates # Context processor to make language and config available in templates
@app.context_processor @app.context_processor
def inject_global_variables(): def inject_global_variables():
from flask import request
lang = get_locale() lang = get_locale()
return { return {
'language': lang, 'language': lang,