Flask-Babel

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-8extensions=jinja2.ext.autoescape,jinja2.ext.with_

We configure Babel to look for text to translate in Python files in the  ...

Get Mastering Flask Web Development - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.