Babel extraction method for Jinja templates. .. versionchanged:: 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
(fileobj, keywords, comment_tags, options)
| 540 | |
| 541 | |
| 542 | def babel_extract(fileobj, keywords, comment_tags, options): |
| 543 | """Babel extraction method for Jinja templates. |
| 544 | |
| 545 | .. versionchanged:: 2.3 |
| 546 | Basic support for translation comments was added. If `comment_tags` |
| 547 | is now set to a list of keywords for extraction, the extractor will |
| 548 | try to find the best preceeding comment that begins with one of the |
| 549 | keywords. For best results, make sure to not have more than one |
| 550 | gettext call in one line of code and the matching comment in the |
| 551 | same line or the line before. |
| 552 | |
| 553 | .. versionchanged:: 2.5.1 |
| 554 | The `newstyle_gettext` flag can be set to `True` to enable newstyle |
| 555 | gettext calls. |
| 556 | |
| 557 | .. versionchanged:: 2.7 |
| 558 | A `silent` option can now be provided. If set to `False` template |
| 559 | syntax errors are propagated instead of being ignored. |
| 560 | |
| 561 | :param fileobj: the file-like object the messages should be extracted from |
| 562 | :param keywords: a list of keywords (i.e. function names) that should be |
| 563 | recognized as translation functions |
| 564 | :param comment_tags: a list of translator tags to search for and include |
| 565 | in the results. |
| 566 | :param options: a dictionary of additional options (optional) |
| 567 | :return: an iterator over ``(lineno, funcname, message, comments)`` tuples. |
| 568 | (comments will be empty currently) |
| 569 | """ |
| 570 | extensions = set() |
| 571 | for extension in options.get('extensions', '').split(','): |
| 572 | extension = extension.strip() |
| 573 | if not extension: |
| 574 | continue |
| 575 | extensions.add(import_string(extension)) |
| 576 | if InternationalizationExtension not in extensions: |
| 577 | extensions.add(InternationalizationExtension) |
| 578 | |
| 579 | def getbool(options, key, default=False): |
| 580 | return options.get(key, str(default)).lower() in \ |
| 581 | ('1', 'on', 'yes', 'true') |
| 582 | |
| 583 | silent = getbool(options, 'silent', True) |
| 584 | environment = Environment( |
| 585 | options.get('block_start_string', BLOCK_START_STRING), |
| 586 | options.get('block_end_string', BLOCK_END_STRING), |
| 587 | options.get('variable_start_string', VARIABLE_START_STRING), |
| 588 | options.get('variable_end_string', VARIABLE_END_STRING), |
| 589 | options.get('comment_start_string', COMMENT_START_STRING), |
| 590 | options.get('comment_end_string', COMMENT_END_STRING), |
| 591 | options.get('line_statement_prefix') or LINE_STATEMENT_PREFIX, |
| 592 | options.get('line_comment_prefix') or LINE_COMMENT_PREFIX, |
| 593 | getbool(options, 'trim_blocks', TRIM_BLOCKS), |
| 594 | getbool(options, 'lstrip_blocks', LSTRIP_BLOCKS), |
| 595 | NEWLINE_SEQUENCE, |
| 596 | getbool(options, 'keep_trailing_newline', KEEP_TRAILING_NEWLINE), |
| 597 | frozenset(extensions), |
| 598 | cache_size=0, |
| 599 | auto_reload=False |
nothing calls this directly
no test coverage detected
searching dependent graphs…