python-babel / babel

The official repository for Babel, the Python Internationalization Library
http://babel.pocoo.org/
BSD 3-Clause "New" or "Revised" License
1.29k stars 433 forks source link

Files in directories starting with underscore (_) are not extratcted into .POT #1024

Closed Porrumentzio closed 2 months ago

Porrumentzio commented 10 months ago

Overview Description

We are using PyBabel for i18n in our software and Jinja2 extension for HTML files. However, files which are located in directories starting with an underscore, e.g. _partials, are not extracted into the .pot file, even if the rest of directories are taken into account. It happens both with .py files and in .html files (using Jinja2)

This is our Babel config file:

[python: liberaforms/models/**.py]
[python: liberaforms/utils/**.py]
[python: liberaforms/views/**.py]
[jinja2: liberaforms/templates/**.html]
[jinja2: liberaforms/templates/**.js]
[jinja2: assets/inline_help/menu.json]
[jinja2: assets/inline_help/pages/**]
extensions=jinja2.ext.loopcontrols

I also tried pointing to the exact file by including the whole path into the Babel config file.

Is the character _ excluded from **?

Steps to Reproduce

  1. Create a directory starting with an underscore, e.g. _test
  2. Reference the directory in your Babel config file
  3. Run pybabel extract command
  4. Check your updated .pot file: the i18n-ed strings in those directories won't be in the .pot

Actual Results

The files under directories starting with underscore are not included into .pot If you change the directory name to start with hyphen (-), the file is included. No matter whether strings are i18n-ed as _("string") or as gettext("string")

Expected Results

If using ** in the Babel config should include all directories (as documentation points out), also directories starting with underscore should be included.

Additional Information

Our code repo: https://gitlab.com/liberaforms/liberaforms/-/tree/develop Our babel config file: https://gitlab.com/liberaforms/liberaforms/-/blob/develop/babel/messages.cfg A real example of directory starting with underscore: https://gitlab.com/liberaforms/liberaforms/-/tree/develop/liberaforms/templates/form/_partials

akx commented 9 months ago

See https://github.com/python-babel/babel/pull/832 – you should be able to use --ignore-dirs=.* to remove the default _* directory ignore filter.