<commit_before>"""
Dealing with internationalization
"""
import datetime

from flask.ext.babel import Babel
from flask import request
from flask_moment import Moment

from app import app
import config

##
## Internationalization
babel = Babel(app)
@babel.localeselector
def get_locale():
    return request.accept_languages.best_match(config.languages.keys())

moment = Moment(app)

@app.context_processor
def inject_locale():
    return dict(
        config=config,
        global_now=datetime.datetime.utcnow(),
        js_dateformat='YYYY-MM-DD',
        js_timeformat='HH:MM:SS',
        js_datetimeformat='YYYY-MM-DD HH:MM:SS'
    )
<commit_msg>Add translation-generating code to i18n.py<commit_after>"""
This module contains code dealing with internationalization.

When imported, it adds the babel configuration to the existing flask app.

When called directly, it updates the "pot" file
"""
if __name__ == '__main__':
    import subprocess, sys, os

    path = os.path.dirname(os.path.abspath(__file__))
    os.chdir(path)
    # noinspection Restricted_Python_calls
    subprocess.check_call('pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot .', shell=True)
    # noinspection Restricted_Python_calls
    subprocess.check_call('pybabel update -i messages.pot -d translations', shell=True)
    # noinspection Restricted_Python_calls
    subprocess.check_call('pybabel compile -d translations', shell=True)
    sys.exit(0)

import datetime

from flask.ext.babel import Babel
from flask import request
from flask_moment import Moment

from app import app
import config

##
## Internationalization
babel = Babel(app)


@babel.localeselector
def get_locale():
    return request.accept_languages.best_match(config.languages.keys())


moment = Moment(app)


@app.context_processor
def inject_locale():
    return dict(
        config=config,
        global_now=datetime.datetime.utcnow(),
        js_dateformat='YYYY-MM-DD',
        js_timeformat='HH:MM:SS',
        js_datetimeformat='YYYY-MM-DD HH:MM:SS'
    )
{'fraction_non_alphanumeric': 0.09871668311944719, 'fraction_numerical': 0.0014807502467917078, 'mean_word_length': 4.237726098191215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '427243', 'n_tokens_mistral': 654, 'n_tokens_neox': 621, 'n_words': 156}