<commit_before>from flask import redirect, request, session, url_for, g
from flask.ext.babel import get_locale
from babel import Locale

from skylines import app


@app.before_request
def inject_active_locale():
    g.available_locales = app.babel_instance.list_translations()
    g.active_locale = get_locale()


@app.babel_instance.localeselector
def select_locale():
    available = map(str, g.available_locales)
    preferred = []

    session_language = session.get('language', None)
    if session_language:
        preferred.append(session_language)

    preferred.extend([l[0] for l in request.accept_languages])

    best_match = Locale.negotiate(preferred, available)
    if best_match:
        return str(best_match)


@app.route('/set_lang/<language>')
def set_lang(language):
    session['language'] = language
    return redirect(request.referrer or url_for('index'))<commit_msg>views/i18n: Cache list of translations on startup<commit_after>from flask import redirect, request, session, url_for, g
from flask.ext.babel import get_locale
from babel import Locale

from skylines import app

available_locales = app.babel_instance.list_translations()


@app.before_request
def inject_active_locale():
    g.available_locales = available_locales
    g.active_locale = get_locale()


@app.babel_instance.localeselector
def select_locale():
    available = map(str, available_locales)
    preferred = []

    session_language = session.get('language', None)
    if session_language:
        preferred.append(session_language)

    preferred.extend([l[0] for l in request.accept_languages])

    best_match = Locale.negotiate(preferred, available)
    if best_match:
        return str(best_match)


@app.route('/set_lang/<language>')
def set_lang(language):
    session['language'] = language
    return redirect(request.referrer or url_for('index'))
{'fraction_non_alphanumeric': 0.0979020979020979, 'fraction_numerical': 0.002151694459386767, 'mean_word_length': 4.723076923076923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1321422', 'n_tokens_mistral': 579, 'n_tokens_neox': 560, 'n_words': 129}