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


Python i18n.Translator类代码示例

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


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

示例1: extract_genshi_strings

def extract_genshi_strings(filename, options=None):
    """Extract translatable strings from a Genshi template.

    The extractor will get all the text inside all elements which are
    not in the ignore list (see options) and the values of all
    attributes named in the include list.

    Options:

    `ignore_tags` -- `'script style'`
        List of element names. Content inside elements named in
        this list is not extracted as translatable text. Can be a
        space-separated string or a list of string.
    `include_attrs` -- `'abbr alt label prompt standby summary title'`
        List of attribute names. Only values of the attributes named in this
        list are extracted as translatable text. Can be a space-separated
        string or a list of string.

    See http://genshi.edgewall.org/wiki/Documentation/0.5.x/i18n.html for
    more information.

    """

    if not GenshiMarkupTemplate:
        raise ImportError("Genshi templating is not installed.")

    if options is None:
        options = {}

    tmpl = open(filename)
    stream = GenshiMarkupTemplate(tmpl, filename=filename).stream
    translator = GenshiTranslator(**options)
    return translator.extract(stream)
开发者ID:marqui678,项目名称:finalchance.Panopta,代码行数:33,代码来源:pygettext.py

示例2: test_ignore_attribute_with_expression

 def test_ignore_attribute_with_expression(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="Reply" title="Reply to comment $num" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
开发者ID:alon,项目名称:polinax,代码行数:7,代码来源:i18n.py

示例3: test_ignore_tag_with_fixed_xml_lang

 def test_ignore_tag_with_fixed_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="en">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(0, len(messages))
开发者ID:alon,项目名称:polinax,代码行数:7,代码来源:i18n.py

示例4: test_extract_text_from_sub

 def test_extract_text_from_sub(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <py:if test="foo">Foo</py:if>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例5: test_extract_gettext_with_unicode_string

 def test_extract_gettext_with_unicode_string(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${gettext("Grüße")}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'gettext', u'Gr\xfc\xdfe'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例6: test_extract_included_attribute_text

 def test_extract_included_attribute_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <span title="Foo"></span>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例7: test_extract_attribute_expr

 def test_extract_attribute_expr(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <input type="submit" value="${_('Save')}" />
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, '_', u'Save'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例8: test_extract_non_included_attribute_interpolated

 def test_extract_non_included_attribute_interpolated(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <a href="#anchor_${num}">Foo</a>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'Foo'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例9: test_extract_tag_with_variable_xml_lang

 def test_extract_tag_with_variable_xml_lang(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p xml:lang="${lang}">(c) 2007 Edgewall Software</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, None, u'(c) 2007 Edgewall Software'), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例10: test_extract_funky_plural_form

 def test_extract_funky_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext(len(items), *widget.display_names)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (None, None)), messages[0])
开发者ID:alon,项目名称:polinax,代码行数:8,代码来源:i18n.py

示例11: test_extract_plural_form

 def test_extract_plural_form(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((2, 'ngettext', (u'Singular', u'Plural', None)),
                      messages[0])
开发者ID:alon,项目名称:polinax,代码行数:9,代码来源:i18n.py

示例12: test_extract_i18n_msg_with_comment

 def test_extract_i18n_msg_with_comment(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="" i18n:comment="As in foo bar">Foo</p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((3, None, u'Foo', ['As in foo bar']), messages[0])
开发者ID:enyst,项目名称:plexnet,代码行数:9,代码来源:i18n.py

示例13: test_extract_without_text

 def test_extract_without_text(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/">
       <p title="Bar">Foo</p>
       ${ngettext("Singular", "Plural", num)}
     </html>""")
     translator = Translator(extract_text=False)
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual((3, 'ngettext', (u'Singular', u'Plural', None)),
                      messages[0])
开发者ID:alon,项目名称:polinax,代码行数:10,代码来源:i18n.py

示例14: test_extract_i18n_msg_multiple

 def test_extract_i18n_msg_multiple(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="">
         Please see <a href="help.html">Help</a> for <em>details</em>.
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Please see [1:Help] for [2:details].', messages[0][2])
开发者ID:alon,项目名称:polinax,代码行数:11,代码来源:i18n.py

示例15: test_extract_i18n_msg_with_param

 def test_extract_i18n_msg_with_param(self):
     tmpl = MarkupTemplate("""<html xmlns:py="http://genshi.edgewall.org/"
         xmlns:i18n="http://genshi.edgewall.org/i18n">
       <p i18n:msg="name">
         Hello, ${user.name}!
       </p>
     </html>""")
     translator = Translator()
     messages = list(translator.extract(tmpl.stream))
     self.assertEqual(1, len(messages))
     self.assertEqual('Hello, %(name)s!', messages[0][2])
开发者ID:alon,项目名称:polinax,代码行数:11,代码来源:i18n.py


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