Pybabel generates empty pot file with jinja2

I encountered the same problem and in my case the issue was specifying input files, i.e. files where to look for strings marked for translation.

When I run pybabel extract -F babel.cfg -o messages.pot as suggested in various tutorials (for example this one) I got pybabel: error: no input files or directories specified error.

The command that finally worked for me was:

pybabel extract -F babel.cfg -o messages.pot --input-dirs=.

After spending hours to figure it out I found the solution, posting for future help if someone will need it.

I had Flask-Assets installed in my templates, apparently if you have it, you need to add in you babel.cfg:

extensions=jinja2.ext.autoescape,jinja2.ext.with_,webassets.ext.jinja2.AssetsExtension

From the Flask-Assets docs:

Otherwise, babel will not extract strings from any templates that include an assets tag.

I'm going to do a pull request that checks if you have Flask-Assets and Flask-Babel installed and you didn't added the right extension, It will give you warning - I think the developer should get some error/warning.


For others who may not be using the Assets Extension as referred in the accepted answer, the problem could lie with the babel.cfg file itself.

For me the problem was with my babel.cfg file which I had taken from this tutorial.

Later when I switched to using the babel.cfg file right from the question here, things worked out nicely for me.

Just for record, here is the babel.cfg file which worked for me.

[python: **.py]
[jinja2: **.html]
encoding = utf-8
extensions=jinja2.ext.autoescape,jinja2.ext.with_