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


Python locale.translate方法代码示例

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


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

示例1: test_csv_bom

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv_bom(self):
        with open(os.path.join(os.path.dirname(__file__), 'csv_translations',
                               'fr_FR.csv'), 'rb') as f:
            char_data = to_unicode(f.read())
        # Re-encode our input data (which is utf-8 without BOM) in
        # encodings that use the BOM and ensure that we can still load
        # it. Note that utf-16-le and utf-16-be do not write a BOM,
        # so we only test whichver variant is native to our platform.
        for encoding in ['utf-8-sig', 'utf-16']:
            tmpdir = tempfile.mkdtemp()
            try:
                with open(os.path.join(tmpdir, 'fr_FR.csv'), 'wb') as f:
                    f.write(char_data.encode(encoding))
                tornado.locale.load_translations(tmpdir)
                locale = tornado.locale.get('fr_FR')
                self.assertIsInstance(locale, tornado.locale.CSVLocale)
                self.assertEqual(locale.translate("school"), u("\u00e9cole"))
            finally:
                shutil.rmtree(tmpdir) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:locale_test.py

示例2: test_csv_bom

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv_bom(self):
        with open(
            os.path.join(os.path.dirname(__file__), "csv_translations", "fr_FR.csv"),
            "rb",
        ) as f:
            char_data = to_unicode(f.read())
        # Re-encode our input data (which is utf-8 without BOM) in
        # encodings that use the BOM and ensure that we can still load
        # it. Note that utf-16-le and utf-16-be do not write a BOM,
        # so we only test whichver variant is native to our platform.
        for encoding in ["utf-8-sig", "utf-16"]:
            tmpdir = tempfile.mkdtemp()
            try:
                with open(os.path.join(tmpdir, "fr_FR.csv"), "wb") as f:
                    f.write(char_data.encode(encoding))
                tornado.locale.load_translations(tmpdir)
                locale = tornado.locale.get("fr_FR")
                self.assertIsInstance(locale, tornado.locale.CSVLocale)
                self.assertEqual(locale.translate("school"), u"\u00e9cole")
            finally:
                shutil.rmtree(tmpdir) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:23,代码来源:locale_test.py

示例3: test_gettext

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_gettext(self):
        tornado.locale.load_gettext_translations(
            os.path.join(os.path.dirname(__file__), "gettext_translations"),
            "tornado_test",
        )
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.GettextLocale))
        self.assertEqual(locale.translate("school"), u"\u00e9cole")
        self.assertEqual(locale.pgettext("law", "right"), u"le droit")
        self.assertEqual(locale.pgettext("good", "right"), u"le bien")
        self.assertEqual(
            locale.pgettext("organization", "club", "clubs", 1), u"le club"
        )
        self.assertEqual(
            locale.pgettext("organization", "club", "clubs", 2), u"les clubs"
        )
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 1), u"le b\xe2ton")
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 2), u"les b\xe2tons") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:20,代码来源:locale_test.py

示例4: test_csv_bom

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv_bom(self):
        with open(os.path.join(os.path.dirname(__file__), 'csv_translations',
                               'fr_FR.csv'), 'rb') as f:
            char_data = to_unicode(f.read())
        # Re-encode our input data (which is utf-8 without BOM) in
        # encodings that use the BOM and ensure that we can still load
        # it. Note that utf-16-le and utf-16-be do not write a BOM,
        # so we only test whichver variant is native to our platform.
        for encoding in ['utf-8-sig', 'utf-16']:
            tmpdir = tempfile.mkdtemp()
            try:
                with open(os.path.join(tmpdir, 'fr_FR.csv'), 'wb') as f:
                    f.write(char_data.encode(encoding))
                tornado.locale.load_translations(tmpdir)
                locale = tornado.locale.get('fr_FR')
                self.assertIsInstance(locale, tornado.locale.CSVLocale)
                self.assertEqual(locale.translate("school"), u"\u00e9cole")
            finally:
                shutil.rmtree(tmpdir) 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:locale_test.py

示例5: test_csv

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv(self):
        tornado.locale.load_translations(
            os.path.join(os.path.dirname(__file__), 'csv_translations'))
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.CSVLocale))
        self.assertEqual(locale.translate("school"), u("\u00e9cole"))

    # tempfile.mkdtemp is not available on app engine. 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:10,代码来源:locale_test.py

示例6: test_gettext

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_gettext(self):
        tornado.locale.load_gettext_translations(
            os.path.join(os.path.dirname(__file__), 'gettext_translations'),
            "tornado_test")
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.GettextLocale))
        self.assertEqual(locale.translate("school"), u("\u00e9cole"))
        self.assertEqual(locale.pgettext("law", "right"), u("le droit"))
        self.assertEqual(locale.pgettext("good", "right"), u("le bien"))
        self.assertEqual(locale.pgettext("organization", "club", "clubs", 1), u("le club"))
        self.assertEqual(locale.pgettext("organization", "club", "clubs", 2), u("les clubs"))
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 1), u("le b\xe2ton"))
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 2), u("les b\xe2tons")) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:locale_test.py

示例7: test_csv

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv(self):
        tornado.locale.load_translations(
            os.path.join(os.path.dirname(__file__), "csv_translations")
        )
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.CSVLocale))
        self.assertEqual(locale.translate("school"), u"\u00e9cole") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:9,代码来源:locale_test.py

示例8: test_csv

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv(self):
        tornado.locale.load_translations(
            os.path.join(os.path.dirname(__file__), 'csv_translations'))
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.CSVLocale))
        self.assertEqual(locale.translate("school"), u("\u00e9cole")) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:8,代码来源:locale_test.py

示例9: test_gettext

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_gettext(self):
        tornado.locale.load_gettext_translations(
            os.path.join(os.path.dirname(__file__), 'gettext_translations'),
            "tornado_test")
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.GettextLocale))
        self.assertEqual(locale.translate("school"), u("\u00e9cole")) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:9,代码来源:locale_test.py

示例10: test_csv

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_csv(self):
        tornado.locale.load_translations(
            os.path.join(os.path.dirname(__file__), 'csv_translations'))
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.CSVLocale))
        self.assertEqual(locale.translate("school"), u"\u00e9cole")

    # tempfile.mkdtemp is not available on app engine. 
开发者ID:tp4a,项目名称:teleport,代码行数:10,代码来源:locale_test.py

示例11: test_gettext

# 需要导入模块: from tornado import locale [as 别名]
# 或者: from tornado.locale import translate [as 别名]
def test_gettext(self):
        tornado.locale.load_gettext_translations(
            os.path.join(os.path.dirname(__file__), 'gettext_translations'),
            "tornado_test")
        locale = tornado.locale.get("fr_FR")
        self.assertTrue(isinstance(locale, tornado.locale.GettextLocale))
        self.assertEqual(locale.translate("school"), u"\u00e9cole")
        self.assertEqual(locale.pgettext("law", "right"), u"le droit")
        self.assertEqual(locale.pgettext("good", "right"), u"le bien")
        self.assertEqual(locale.pgettext("organization", "club", "clubs", 1), u"le club")
        self.assertEqual(locale.pgettext("organization", "club", "clubs", 2), u"les clubs")
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 1), u"le b\xe2ton")
        self.assertEqual(locale.pgettext("stick", "club", "clubs", 2), u"les b\xe2tons") 
开发者ID:tp4a,项目名称:teleport,代码行数:15,代码来源:locale_test.py


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