In this section, we will explore a way to enable internationalization for our blog. This is an essential feature for building global websites with multi-language support. We will be using the Flask-Babel extension, again created by the author of Flask. As always, we will make sure this dependency exists in our requirements.txt:
...
Flask-Babel
...
Flask-Babel uses the Babel Python library for i18 and localization, and adds some utilities and Flask integration. To use Flask-Babel, first we need to configure Babel in the babel/babel.cfg file:
[python: webapp/**.py]
[jinja2: webapp/templates/**.html]
encoding = utf-8
extensions=jinja2.ext.autoescape,jinja2.ext.with_
We configure Babel to look for text to translate in Python files in the webapp directory only, and to extract text from Jinja2 templates in the webapp/templates directory.
Then, we need to create a translations...