Class | Extension |
No summary |
Constant | GETTEXT_FUNCTIONS |
Undocumented |
Class | _CommentFinder |
No summary |
Class | _TranslationsBasic |
Undocumented |
Class | _TranslationsContext |
Undocumented |
Class | AutoEscapeExtension |
Undocumented |
Class | DebugExtension |
A {% debug %} tag that dumps the available variables, filters, and tests. |
Class | ExprStmtExtension |
Adds a do tag to Jinja that works like the print statement just that it doesn't print the return value. |
Class | InternationalizationExtension |
This extension adds gettext support to Jinja. |
Class | LoopControlExtension |
Adds break and continue to the template engine. |
Class | WithExtension |
Undocumented |
Function | _gettext_alias |
Undocumented |
Function | _make_new_gettext |
Undocumented |
Function | _make_new_ngettext |
Undocumented |
Function | _make_new_npgettext |
Undocumented |
Function | _make_new_pgettext |
Undocumented |
Function | babel_extract |
Babel extraction method for Jinja templates. |
Function | extract_from_ast |
No summary |
Variable | _SupportedTranslations |
Undocumented |
Variable | _ws_re |
Undocumented |
t.Tuple[ str, ...]
=
Undocumented
Value |
|
Undocumented
Parameters | |
func:t.Callable[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
func:t.Callable[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
func:t.Callable[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Undocumented
Parameters | |
func:t.Callable[ | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Babel extraction method for Jinja templates.
comment_tags
is now set to a list of keywords for extraction, the extractor will
try to find the best preceding 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.newstyle_gettext
flag can be set to True
to enable newstyle
gettext calls.silent
option can now be provided. If set to False
template
syntax errors are propagated instead of being ignored.Parameters | |
fileobj:t.BinaryIO | the file-like object the messages should be extracted from |
keywords:t.Sequence[ | a list of keywords (i.e. function names) that should be recognized as translation functions |
comment_tags:t.Sequence[ | a list of translator tags to search for and include in the results. |
options:t.Dict[ | a dictionary of additional options (optional) |
Returns | |
t.Iterator[ | an iterator over (lineno, funcname, message, comments) tuples. (comments will be empty currently) |
Extract localizable strings from the given template node. Per
default this function returns matches in babel style that means non string
parameters as well as keyword arguments are returned as None
. This
allows Babel to figure out what you really meant if you are using
gettext functions that allow keyword arguments for placeholder expansion.
If you don't want that behavior set the babel_style
parameter to False
which causes only strings to be returned and parameters are always stored
in tuples. As a consequence invalid gettext calls (calls without a single
string parameter or string parameters after non-string parameters) are
skipped.
This example explains the behavior:
>>> from jinja2 import Environment >>> env = Environment() >>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}') >>> list(extract_from_ast(node)) [(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))] >>> list(extract_from_ast(node, babel_style=False)) [(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))]
For every string found this function yields a (lineno, function, message) tuple, where:
This extraction function operates on the AST and is because of that unable to extract any comments. For comment support you have to use the babel extraction interface or extract comments yourself.
Parameters | |
ast:nodes.Template | Undocumented |
gettext_functions:t.Sequence[ | Undocumented |
babel_style:bool | Undocumented |
Returns | |
t.Iterator[ | Undocumented |