babel icon indicating copy to clipboard operation
babel copied to clipboard

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

Open rbu opened this issue 11 years ago • 3 comments

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 #125)

rbu avatar Nov 25 '14 09:11 rbu

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.

rbu avatar Nov 25 '14 09:11 rbu

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

rlam3 avatar May 03 '16 22:05 rlam3

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.

m-aciek avatar Jan 29 '23 00:01 m-aciek