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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.