From 49dc3895515b5b43f9e9fa801d450041dd8d0301 Mon Sep 17 00:00:00 2001 From: n0liu <44688300+n0liu@users.noreply.github.com> Date: Thu, 3 Dec 2026 17:49:20 +0800 Subject: [PATCH] Document how to exclude files from message extraction Show the ignore mapping before the Python extractor and explain how an input directory determines the paths matched by both mapping formats. Co-Authored-By: Claude Code --- docs/messages.rst | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/messages.rst b/docs/messages.rst index 3ab62489a..73a1f8c2a 100644 --- a/docs/messages.rst +++ b/docs/messages.rst @@ -120,8 +120,9 @@ Genshi markup templates and text templates: .. code-block:: ini - # Extraction from Python source files + # Skip vendored Python files; extract from all other Python files + [ignore: vendor/**.py] [python: **.py] # Extraction from Genshi HTML and text templates @@ -147,6 +148,13 @@ two subsequent asterisk characters (``**``) can be used to make the wildcard match any directory level, so the pattern ``**.txt`` matches any file with the extension ``.txt`` in any directory. +When extracting from a directory, Babel matches each file's path relative to +that directory and uses the first matching method. For example, with +``pybabel extract -F babel.cfg -o messages.pot src``, the path matched for +``src/vendor/example.py`` is ``vendor/example.py``. Put the ``ignore`` mapping +before ``[python: **.py]`` as shown above; otherwise the Python extractor will +process the vendored file too. + Babel supports two configuration file formats: INI and TOML. INI Configuration Format @@ -177,7 +185,11 @@ The same configuration examples shown above can be written in TOML format: .. code-block:: toml - # Extraction from Python source files + # Skip vendored Python files; extract from all other Python files + [[mappings]] + method = "ignore" + pattern = "vendor/**.py" + [[mappings]] method = "python" pattern = "**.py"