当前位置: 首页>>代码示例>>Python>>正文


Python extract.extract_javascript函数代码示例

本文整理汇总了Python中babel.messages.extract.extract_javascript函数的典型用法代码示例。如果您正苦于以下问题:Python extract_javascript函数的具体用法?Python extract_javascript怎么用?Python extract_javascript使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了extract_javascript函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_misplaced_comments

    def test_misplaced_comments(self):
        buf = BytesIO(
            b"""\
/* NOTE: this won't show up */
foo()

/* NOTE: this will */
msg = _('Something')

// NOTE: this will show up
// too.
msg = _('Something else')

// NOTE: but this won't
bar()

_('no comment here')
"""
        )
        messages = list(extract.extract_javascript(buf, ("_",), ["NOTE:"], {}))
        self.assertEqual(u"Something", messages[0][2])
        self.assertEqual([u"NOTE: this will"], messages[0][3])
        self.assertEqual(u"Something else", messages[1][2])
        self.assertEqual([u"NOTE: this will show up", "too."], messages[1][3])
        self.assertEqual(u"no comment here", messages[2][2])
        self.assertEqual([], messages[2][3])
开发者ID:ENuge,项目名称:babel,代码行数:26,代码来源:test_extract.py

示例2: test_jsx_extraction

def test_jsx_extraction(jsx_enabled):
    buf = BytesIO(JSX_SOURCE)
    messages = [m[2] for m in extract.extract_javascript(buf, ('_', 'gettext'), [], {"jsx": jsx_enabled})]
    if jsx_enabled:
        assert messages == EXPECTED_JSX_MESSAGES
    else:
        assert messages != EXPECTED_JSX_MESSAGES
开发者ID:JonathanRRogers,项目名称:babel,代码行数:7,代码来源:test_js_extract.py

示例3: test_message_with_line_comment

    def test_message_with_line_comment(self):
        buf = BytesIO(u"""\
// NOTE: hello
msg = _('Bonjour à tous')
""".encode('utf-8'))
        messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u'Bonjour à tous', messages[0][2])
        self.assertEqual([u'NOTE: hello'], messages[0][3])
开发者ID:FlowSea,项目名称:babel,代码行数:8,代码来源:test_extract.py

示例4: test_message_with_line_comment

def test_message_with_line_comment():
    buf = BytesIO(u"""\
// NOTE: hello
msg = _('Bonjour à tous')
""".encode('utf-8'))
    messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
    assert messages[0][2] == u'Bonjour à tous'
    assert messages[0][3] == [u'NOTE: hello']
开发者ID:JonathanRRogers,项目名称:babel,代码行数:8,代码来源:test_js_extract.py

示例5: test_ignore_function_definitions

    def test_ignore_function_definitions(self):
        buf = StringIO("""\
function gettext(value) {
    return translations[language][value] || value;
}""")

        messages = list(extract.extract_javascript(buf, ('gettext',), [], {}))
        self.assertEqual(messages, [])
开发者ID:10sr,项目名称:hue,代码行数:8,代码来源:extract.py

示例6: extract_javascript_msgids

def extract_javascript_msgids(source):
    """Return message ids of translateable strings in JS source."""

    extracted = extract_javascript(
        fileobj=StringIO(source), keywords={"_": None, "P_": (1, 2), "N_": None}, comment_tags={}, options={}
    )

    return [msg_id for line, func, msg_id, comments in extracted]
开发者ID:ryancoleman,项目名称:reddit,代码行数:8,代码来源:translation.py

示例7: test_ignore_function_definitions

def test_ignore_function_definitions():
    buf = BytesIO(b"""\
function gettext(value) {
return translations[language][value] || value;
}""")

    messages = list(extract.extract_javascript(buf, ('gettext',), [], {}))
    assert not messages
开发者ID:JonathanRRogers,项目名称:babel,代码行数:8,代码来源:test_js_extract.py

示例8: test_message_with_line_comment

    def test_message_with_line_comment(self):
        buf = StringIO("""\
// NOTE: hello
msg = _('Bonjour à tous')
""")
        messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual('Bonjour \xe0 tous', messages[0][2])
        self.assertEqual(['NOTE: hello'], messages[0][3])
开发者ID:vsajip,项目名称:babel3,代码行数:8,代码来源:extract.py

示例9: test_message_with_multiple_line_comments

    def test_message_with_multiple_line_comments(self):
        buf = StringIO("""\
// NOTE: hello
// goodbye
msg = _('Bonjour à tous')
""")
        messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u'Bonjour à tous', messages[0][2])
        self.assertEqual([u'NOTE: hello goodbye'], messages[0][3])
开发者ID:Khan,项目名称:babel,代码行数:9,代码来源:test_extract.py

示例10: test_message_with_multiline_comment

    def test_message_with_multiline_comment(self):
        buf = StringIO("""\
/* NOTE: hello
   and bonjour
     and servus */
msg = _('Bonjour à tous')
""")
        messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
        self.assertEqual(u'Bonjour à tous', messages[0][2])
        self.assertEqual([u'NOTE: hello', 'and bonjour', '  and servus'], messages[0][3])
开发者ID:10sr,项目名称:hue,代码行数:10,代码来源:extract.py

示例11: test_message_with_line_comment

    def test_message_with_line_comment(self):
        buf = BytesIO(
            u"""\
// NOTE: hello
msg = _('Bonjour à tous')
""".encode(
                "utf-8"
            )
        )
        messages = list(extract.extract_javascript(buf, ("_",), ["NOTE:"], {}))
        self.assertEqual(u"Bonjour à tous", messages[0][2])
        self.assertEqual([u"NOTE: hello"], messages[0][3])
开发者ID:ENuge,项目名称:babel,代码行数:12,代码来源:test_extract.py

示例12: extract_javascript_script

    def extract_javascript_script(fileobj, keywords, comment_tags, options):
        """Extract messages from Javascript embedding in <script> tags.

        Select <script type="javascript/text"> tags and delegate to
        `extract_javascript`.
        """
        from genshi.core import Stream
        from genshi.input import XMLParser

        out = StringIO()
        stream = Stream(XMLParser(fileobj))
        stream.select('//script[@type="text/javascript"]').render(out=out)
        out.seek(0)
        return extract_javascript(out, keywords, comment_tags, options)
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:14,代码来源:dist.py

示例13: extract_mxml

def extract_mxml(fileobj, keywords, comment_tags, options):
    for elem, pos in MXMLParser(fileobj).parse():
        if elem.tag == 'mx:Script':
            for lineno, funcname, message, comments in \
                            extract_javascript(StringIO(elem.text), keywords,
                                                 comment_tags, options):
                yield pos[0]+lineno, funcname, message, comments
        else:
            attrib = None
            for attr in options.get('attrs', []):
                if elem.get(attr):
                    attrib = attr
            if attrib:
                if elem.attrib[attrib].startswith('{') and \
                    elem.attrib[attrib].endswith('}'):
                    for _, funcname, message, comments in extract_actionscript(
                                        StringIO(elem.attrib[attrib][1:-1]),
                                        keywords, comment_tags, options):
                        yield pos[0], funcname, message, comments
开发者ID:UfSoft,项目名称:SSHg,代码行数:19,代码来源:translations.py

示例14: extract_javascript

def extract_javascript(fileobj, keywords, comment_tags, options):
    """Extract messages from Javascript source files. This extractor delegates
    to babel's buit-in javascript extractor, but adds a special comment
    used as a flag to identify web translations. 

    :param fileobj: the file-like object the messages should be extracted
                    from
    :param keywords: a list of keywords (i.e. function names) that should
                     be recognized as translation functions
    :param comment_tags: a list of translator tags to search for and
                         include in the results
    :param options: a dictionary of additional options (optional)
    :return: an iterator over ``(lineno, funcname, message, comments)``
             tuples
    :rtype: ``iterator``
    """
    for (message_lineno, funcname, messages, comments) in \
        extract.extract_javascript(fileobj, keywords, comment_tags, options):
        comments.append(TRANSLATION_FLAG_COMMENT)
        yield (message_lineno, funcname, messages, comments)
开发者ID:Cywaithaka,项目名称:LibrERP,代码行数:20,代码来源:npybabel.py

示例15: extract_mxml

def extract_mxml(fileobj, keywords, comment_tags, options):
    attrs = set(options.get('attrs', [])).union(
                set([u'label', u'text', u'title', u'headerText', u'prompt']))
    encoding = options.get('encoding', 'utf-8')

    for elem, pos in MXMLParser(fileobj).parse():
        if elem.tag == 'mx:Script':
            for lineno, funcname, message, comments in \
                            extract_javascript(StringIO(elem.text), keywords,
                                                 comment_tags, options):
                yield pos[0]+lineno, funcname, message, comments
        else:
            attrib = None
            for attr in attrs:
                if elem.get(attr):
                    attrib = attr
            if attrib:
                if elem.attrib[attrib].startswith('{') and \
                    elem.attrib[attrib].endswith('}'):
                    contents = elem.attrib[attrib][1:-1].encode(encoding)
                    for _, funcname, message, comments in extract_actionscript(
                          StringIO(contents), keywords, comment_tags, options):
                        yield pos[0], funcname, message, comments
开发者ID:UfSoft,项目名称:dac,代码行数:23,代码来源:extract.py


注:本文中的babel.messages.extract.extract_javascript函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。