Where should the python babel mapping configuration file be placed or named for standalone script?

Question:

I am currently trying to use Babel to generate a set of static html pages in different languages using Jinja2 within a simple script (not as part of a web app)

I am at the point where I need to extract the messages for translation and I know that I am supposed to modify the Babel mapping configuration file to understand Jinja2 templates.Since I am using the commandline tool, I assume I need to create the mapping file myself.

However, I can’t seem to find in the documentation what the mapping configuration file should be named and where it should be placed. All I know is that I need to place the following:

[jinja2: **/templates/**.html]
encoding = utf-8

into the mapping file according to the Jinja2 documentation. Has anyone done something similar or know what the mapping configuration file should be? Thanks!

Asked By: sasker

||

Answers:

You can specify the location of the configuration file with -c <filename>.

Answered By: moinudin

Mapping file location is read from setup.cfg file (generated by Distutils), in the section “extract_messages”. In this section you must add setting named mapping_file, which should point to Your mapping file.

Example:

This tells Babel to look for mapping file named message-extraction.ini in package directory.

[extract_messages]
# some default options
# ..
mapping_file = message-extraction.ini
Answered By: agrzelak

You can specify the path to the mapping configuration file for extract_messages using -F. For example, my mapping configuration is in babel.cfg, located at the root of my project. When extracting messages, I run:

pybabel extract -F babel.cfg ...
Answered By: Ilya