MCPcopy Create free account
hub / github.com/nodejs/node / babel_extract

Function babel_extract

deps/v8/third_party/jinja2/ext.py:763–852  ·  view source on GitHub ↗

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 preceding comment that begins with one of the

(
    fileobj: t.BinaryIO,
    keywords: t.Sequence[str],
    comment_tags: t.Sequence[str],
    options: t.Dict[str, t.Any],
)

Source from the content-addressed store, hash-verified

761
762
763def babel_extract(
764 fileobj: t.BinaryIO,
765 keywords: t.Sequence[str],
766 comment_tags: t.Sequence[str],
767 options: t.Dict[str, t.Any],
768) -> t.Iterator[
769 t.Tuple[
770 int, str, t.Union[t.Optional[str], t.Tuple[t.Optional[str], ...]], t.List[str]
771 ]
772]:
773 """Babel extraction method for Jinja templates.
774
775 .. versionchanged:: 2.3
776 Basic support for translation comments was added. If `comment_tags`
777 is now set to a list of keywords for extraction, the extractor will
778 try to find the best preceding comment that begins with one of the
779 keywords. For best results, make sure to not have more than one
780 gettext call in one line of code and the matching comment in the
781 same line or the line before.
782
783 .. versionchanged:: 2.5.1
784 The `newstyle_gettext` flag can be set to `True` to enable newstyle
785 gettext calls.
786
787 .. versionchanged:: 2.7
788 A `silent` option can now be provided. If set to `False` template
789 syntax errors are propagated instead of being ignored.
790
791 :param fileobj: the file-like object the messages should be extracted from
792 :param keywords: a list of keywords (i.e. function names) that should be
793 recognized as translation functions
794 :param comment_tags: a list of translator tags to search for and include
795 in the results.
796 :param options: a dictionary of additional options (optional)
797 :return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
798 (comments will be empty currently)
799 """
800 extensions: t.Dict[t.Type[Extension], None] = {}
801
802 for extension_name in options.get("extensions", "").split(","):
803 extension_name = extension_name.strip()
804
805 if not extension_name:
806 continue
807
808 extensions[import_string(extension_name)] = None
809
810 if InternationalizationExtension not in extensions:
811 extensions[InternationalizationExtension] = None
812
813 def getbool(options: t.Mapping[str, str], key: str, default: bool = False) -> bool:
814 return options.get(key, str(default)).lower() in {"1", "on", "yes", "true"}
815
816 silent = getbool(options, "silent", True)
817 environment = Environment(
818 options.get("block_start_string", defaults.BLOCK_START_STRING),
819 options.get("block_end_string", defaults.BLOCK_END_STRING),
820 options.get("variable_start_string", defaults.VARIABLE_START_STRING),

Callers

nothing calls this directly

Calls 14

parseMethod · 0.95
lexMethod · 0.95
preprocessMethod · 0.95
import_stringFunction · 0.70
getboolFunction · 0.70
EnvironmentClass · 0.70
_CommentFinderClass · 0.70
extract_from_astFunction · 0.70
getMethod · 0.65
decodeMethod · 0.65
listFunction · 0.50
splitMethod · 0.45

Tested by

no test coverage detected