jinja2.ext.babel_extract

jinja2.ext.babel_extract(fileobj, keywords, comment_tags, options)[source]

Babel extraction method for Jinja templates.

Changed in version 2.3: Basic support for translation comments was added. If comment_tags is now set to a list of keywords for extraction, the extractor will try to find the best preceeding comment that begins with one of the keywords. For best results, make sure to not have more than one gettext call in one line of code and the matching comment in the same line or the line before.

Changed in version 2.5.1: The newstyle_gettext flag can be set to True to enable newstyle gettext calls.

Changed in version 2.7: A silent option can now be provided. If set to False template syntax errors are propagated instead of being ignored.

Parameters:
  • fileobj – the file-like object the messages should be extracted from
  • keywords – a list of keywords (i.e. function names) that should be recognized as translation functions
  • comment_tags – a list of translator tags to search for and include in the results.
  • options – a dictionary of additional options (optional)
Returns:

an iterator over (lineno, funcname, message, comments) tuples. (comments will be empty currently)