Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TJTS5901 K23 Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Startuplab
Courses
TJTS5901 Continuous Software Engineering
TJTS5901 K23 Template
Commits
dfa07016
Commit
dfa07016
authored
2 years ago
by
Teemu Autto
Browse files
Options
Downloads
Patches
Plain Diff
Basic babel integration for Flask.
parent
01e91ce5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/tjts5901/app.py
+4
-0
4 additions, 0 deletions
src/tjts5901/app.py
src/tjts5901/i18n.py
+30
-0
30 additions, 0 deletions
src/tjts5901/i18n.py
with
34 additions
and
0 deletions
src/tjts5901/app.py
+
4
−
0
View file @
dfa07016
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
src/tjts5901/i18n.py
0 → 100644
+
30
−
0
View file @
dfa07016
"""
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment