feat(i18n & ux): auditoria, traduccion completa, correcciones ux y gestion de idioma en perfil

This commit is contained in:
Carlos Tello
2026-09-02 23:45:13 -03:00
parent 3d4e9992f8
commit d1d4be0428
31 changed files with 2356 additions and 488 deletions
+23 -17
View File
@@ -41,28 +41,34 @@ def create_app(config_class=Config):
app.register_blueprint(genetic_bp)
app.register_blueprint(genetic_web_bp)
# Babel language selector
# Language selector function
def get_locale():
# 1. Check if language is explicitly set in URL parameters
lang = request.args.get('lang')
if lang and lang in app.config['LANGUAGES']:
return lang
# 2. Check if user is authenticated and has a configured language in profile
from flask_login import current_user
if current_user.is_authenticated and getattr(current_user, 'preferred_language', None):
if current_user.preferred_language in app.config['LANGUAGES']:
return current_user.preferred_language
# 3. Check if language is stored in session (e.g. manual switcher)
if 'language' in session and session['language'] in app.config['LANGUAGES']:
return session['language']
# 4. Check browser language preference by default (especially on login/guest)
return request.accept_languages.best_match(app.config['LANGUAGES']) or app.config['BABEL_DEFAULT_LOCALE']
# Babel context processor
@app.context_processor
def inject_conf_vars():
return dict(
languages=app.config['LANGUAGES'],
current_lang=session.get('language', request.accept_languages.best_match(app.config['LANGUAGES']) or app.config['BABEL_DEFAULT_LOCALE'])
current_lang=str(get_locale())
)
# Language selector function
def get_locale():
# 1. Check if language is explicitly set in URL parameters
if request.args.get('lang'):
lang = request.args.get('lang')
if lang in app.config['LANGUAGES']:
return lang
# 2. Check if language is stored in session
if 'language' in session:
return session['language']
# 3. Check browser language preference
return request.accept_languages.best_match(app.config['LANGUAGES']) or app.config['BABEL_DEFAULT_LOCALE']
# Configure Babel
babel.init_app(app, locale_selector=get_locale)