4

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!

desertnaut
  • 57,590
  • 26
  • 140
  • 166
sasker
  • 2,221
  • 2
  • 21
  • 26

3 Answers3

2

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

Martin
  • 157
  • 1
  • 3
  • 8
moinudin
  • 134,091
  • 45
  • 190
  • 216
  • Thanks, should have paid more attention to the options. – sasker Dec 25 '10 at 09:43
  • 1
    This answer is incorrect. `-c` is related to comments. The link in this answer links to a different program,`babeld`, which is an "ad-hoc network routing daemon." See my answer below for the correct flag for specifying the mapping configuration file. – Ilya Sep 30 '21 at 13:09
2

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
agrzelak
  • 21
  • 1
0

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 ...
Ilya
  • 143
  • 1
  • 14