Skip to content
Snippets Groups Projects
Commit dfa07016 authored by Teemu Autto's avatar Teemu Autto
Browse files

Basic babel integration for Flask.

parent 01e91ce5
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,7 @@ from flask import (
from .utils import get_version
from .db import init_db
from .i18n import init_babel
logger = logging.getLogger(__name__)
......@@ -55,6 +56,9 @@ def create_app(config: Optional[Dict] = None) -> Flask:
except OSError:
pass
# Initialize the Flask-Babel extension.
init_babel(flask_app)
# Initialize the database connection.
init_db(flask_app)
......
"""
Internationalisation and localisation support for the application.
"""
from flask_babel import Babel
from babel import Locale
from babel import __version__ as babel_version
from flask import Flask
import logging
logger = logging.getLogger(__name__)
def init_babel(flask_app: Flask):
"""
Initialize the Flask-Babel extension.
"""
# Configure the Flask-Babel extension.
# Try setting the default locale from underlying OS. Falls back into English.
system_language = Locale.default().language
flask_app.config.setdefault("BABEL_DEFAULT_LOCALE", system_language)
# TODO: Set the default timezone from underlying OS.
babel = Babel(flask_app)
logger.info("Initialized Flask-Babel extension %s.", babel_version,
extra=flask_app.config.get_namespace("BABEL_"))
return babel
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment