• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python extract.extract_javascript函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: test_misplaced_comments

def test_misplaced_comments():
    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:'], {}))
    assert messages[0][2] == u'Something'
    assert messages[0][3] == [u'NOTE: this will']
    assert messages[1][2] == u'Something else'
    assert messages[1][3] == [u'NOTE: this will show up', 'too.']
    assert messages[2][2] == u'no comment here'
    assert messages[2][3] == []
开发者ID:JonathanRRogers,项目名称:babel,代码行数:24,代码来源:test_js_extract.py


示例17: test_misplaced_comments

    def test_misplaced_comments(self):
        buf = StringIO("""\
/* 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:10sr,项目名称:hue,代码行数:24,代码来源:extract.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python extract.extract_python函数代码示例发布时间:2022-05-24
下一篇:
Python extract.extract_from_dir函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap