Skip to content

Excluding files from message extraction is under-documented (ignore) #124

Description

@rbu

I was trying to exclude a folder from message extraction through an ignore rule in the mapping file, and ended up having to read the source code to find out how to do it. Some of the questions that are not answered in the documentation are:

  • How to specify the ignore filter (A: [ignore: something/**.txt])
  • How does Babel evaluate the priority in the mapping? (A: By first match, so ignore rules need to be listed first)
  • What is the path that is matched against? (A: The file path without the package name, see Message extraction mapping does not match against package name #125)

Activity

  1. rbu commented on Nov 25, 2014

    @rbu
    Author

    So, after quite some debugging, a rule to exclude "awesomepackage/contrib" must be written as such:

    [ignore: contrib/**]
    
    [jinja2: **/templates/**.jinja2]
    encoding = utf-8
    extensions=jinja2.ext.autoescape,jinja2.ext.with_
    
    [python: **.py]
    

    If the babel.cfg, setup.cfg and "awesomepackage" are within the same directory.

  2. rlam3 commented on May 3, 2016

    @rlam3

    Is there a way for us to ignore the entire contrib folder but at the same time have [python: **.py] not look there either? If I have the following tree:

    -app
    --mod1
    --static
    ----js
    ----css
    ----node_modules

    Id like to ignore the entire node_modules directory and not have

    python:**.py check that directory. Is there a way for this?

    The closest I got was:

    [ignore: static/node_modules/]
    [jinja2: templates/**/**.html]
    encoding = utf-8
    extensions=jinja2.ext.autoescape,jinja2.ext.with_
    [python: **.py]
    

    However jinja2 and python are always checking into static even though it is ignored..

    You can see this happening in the check_and_call_extract_file method of extract.py

    for pattern, method in method_map:
        print (method,filename) <<< this shows you all the things it is trying to match I believe
    
  3. added a commit that references this issue on Oct 3, 2021
    956652e
  4. m-aciek commented on Jan 29, 2023

    @m-aciek
    Contributor

    Note: since 2.10 extract accepts --ignore-dirs option with space-separated glob patterns.

    I've added a PR #963 with adding them to the documentation.

  5. NewComer00 commented on Mar 1, 2026

    @NewComer00

    For project using pyproject.toml as the configuration file, here is an example to exclude files:

    [tool.babel]
    [[tool.babel.mappings]]
    method = "ignore"
    pattern = ["tests/**.py", "dist/**.py", "build/**.py"]
    
    [[tool.babel.mappings]]
    method = "python"
    pattern = "**.py"
    encoding = "utf-8"
    keywords = ["_", "_l"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions