diff --git a/app.py b/app.py index f9054c7..807be11 100644 --- a/app.py +++ b/app.py @@ -13,9 +13,6 @@ from flask_babel import Babel, gettext, lazy_gettext app = Flask(__name__) app.secret_key = 'your_secret_key_here' -# Babel configuration -babel = Babel(app) - # Configure supported languages app.config['BABEL_DEFAULT_LOCALE'] = 'es' app.config['LANGUAGES'] = { @@ -26,7 +23,7 @@ app.config['LANGUAGES'] = { # Configure translation directory app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations' -@babel.locale_selector +# Locale selector function def get_locale(): # Try to get language from URL parameter lang = request.args.get('lang') @@ -38,6 +35,9 @@ def get_locale(): # Try to get from browser preferences return request.accept_languages.best_match(app.config['LANGUAGES'].keys()) +# Initialize Babel with locale selector +babel = Babel(app, locale_selector=get_locale) + # Context processor to make language and config available in templates @app.context_processor def inject_global_variables():