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


Python Translations.ugettext方法代码示例

本文整理汇总了Python中babel.support.Translations.ugettext方法的典型用法代码示例。如果您正苦于以下问题:Python Translations.ugettext方法的具体用法?Python Translations.ugettext怎么用?Python Translations.ugettext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在babel.support.Translations的用法示例。


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

示例1: test_sorting

# 需要导入模块: from babel.support import Translations [as 别名]
# 或者: from babel.support.Translations import ugettext [as 别名]
    def test_sorting(self):
        # Ensure the header is sorted to the first entry so that its charset
        # can be applied to all subsequent messages by GNUTranslations
        # (ensuring all messages are safely converted to unicode)
        catalog = Catalog(locale='en_US')
        catalog.add(u'', '''\
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n''')
        catalog.add(u'foo', 'Voh')
        catalog.add((u'There is', u'There are'), (u'Es gibt', u'Es gibt'))
        catalog.add(u'Fizz', '')
        catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
        buf = BytesIO()
        mofile.write_mo(buf, catalog)
        buf.seek(0)
        translations = Translations(fp=buf)
        self.assertEqual(u'Voh', translations.ugettext('foo'))
        assert isinstance(translations.ugettext('foo'), text_type)
        self.assertEqual(u'Es gibt', translations.ungettext('There is', 'There are', 1))
        assert isinstance(translations.ungettext('There is', 'There are', 1), text_type)
        self.assertEqual(u'Fizz', translations.ugettext('Fizz'))
        assert isinstance(translations.ugettext('Fizz'), text_type)
        self.assertEqual(u'Fuzz', translations.ugettext('Fuzz'))
        assert isinstance(translations.ugettext('Fuzz'), text_type)
        self.assertEqual(u'Fuzzes', translations.ugettext('Fuzzes'))
        assert isinstance(translations.ugettext('Fuzzes'), text_type)
开发者ID:python-babel,项目名称:babel,代码行数:28,代码来源:test_mofile.py

示例2: test_empty_translation_with_fallback

# 需要导入模块: from babel.support import Translations [as 别名]
# 或者: from babel.support.Translations import ugettext [as 别名]
    def test_empty_translation_with_fallback(self):
        catalog1 = Catalog(locale='fr_FR')
        catalog1.add(u'', '''\
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n''')
        catalog1.add(u'Fuzz', '')
        buf1 = BytesIO()
        mofile.write_mo(buf1, catalog1)
        buf1.seek(0)
        catalog2 = Catalog(locale='fr')
        catalog2.add(u'', '''\
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n''')
        catalog2.add(u'Fuzz', 'Flou')
        buf2 = BytesIO()
        mofile.write_mo(buf2, catalog2)
        buf2.seek(0)

        translations = Translations(fp=buf1)
        translations.add_fallback(Translations(fp=buf2))

        self.assertEqual(u'Flou', translations.ugettext('Fuzz'))
开发者ID:python-babel,项目名称:babel,代码行数:24,代码来源:test_mofile.py


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