本文整理匯總了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)
示例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))
示例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))
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])
示例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])