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


Python POHandler.compile方法代码示例

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


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

示例1: test_order

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import compile [as 别名]
 def test_order(self):
     handler = POHandler(os.path.join(
             os.path.dirname(__file__), 'copyright.po')
     )
     handler.bind_resource(self.resource)
     handler.set_language(self.resource.source_language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     cr = Copyright.objects.assign(
         language=self.language_en, resource=self.resource,
         owner='CC', year='2014')
     cr = Copyright.objects.assign(
         language=self.language_en, resource=self.resource,
         owner='ZZ', year='2014')
     cr = Copyright.objects.assign(
         language=self.language_en, resource=self.resource,
         owner='BA', year='2015')
     handler.compile()
     lines_iterator = handler.compiled_template.split("\n")
     for n, line in enumerate(lines_iterator):
         if line == "## Translators:":
             break
     line = lines_iterator[n + 1]
     self.assertTrue('AB' in line)
     line = lines_iterator[n + 3]
     self.assertTrue('BA' in line)
     line = lines_iterator[n + 4]
     self.assertTrue('CC' in line)
     line = lines_iterator[n + 6]
     self.assertTrue('ZZ' in line)
开发者ID:hfeeki,项目名称:transifex,代码行数:32,代码来源:__init__.py

示例2: test_copyright_on_save

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import compile [as 别名]
 def test_copyright_on_save(self):
     handler = POHandler(os.path.join(
             os.path.dirname(__file__), 'copyright.po')
     )
     handler.bind_resource(self.resource)
     handler.set_language(self.resource.source_language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     handler.compile()
     self.assertTrue("AB" in handler.compiled_template)
开发者ID:hfeeki,项目名称:transifex,代码行数:12,代码来源:__init__.py

示例3: test_general_po

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import compile [as 别名]
    def test_general_po(self):
        """
        Test with a PO file containing multiple different 'breakable'
        cases.
        """

        # Empty our resource
        SourceEntity.objects.filter(resource=self.resource).delete()

        # Import file with two senteces
        handler = POHandler('%s/general/test.pot' %
            os.path.split(__file__)[0])
        handler.bind_resource(self.resource)
        handler.set_language(self.resource.source_language)
        handler.parse_file(is_source=True)
        handler.save2db(is_source=True)

        handler.compile()

        exported_file = polib.pofile(handler.compiled_template)

        for entry in exported_file:
            se = SourceEntity.objects.get(
               string = entry.msgid,
               context = entry.msgctxt or 'None',
               resource = self.resource
            )

            if se.pluralized:
                plurals = Translation.objects.filter(
                    source_entity__resource = self.resource,
                    language = self.resource.source_language,
                    source_entity__string = entry.msgid
                ).order_by('rule')

                plural_keys = {}
                # last rule excluding other(5)
                lang_rules = self.resource.source_language.get_pluralrules_numbers()
                # Initialize all plural rules up to the last
                for p,n in enumerate(lang_rules):
                    plural_keys[str(p)] = ""
                for n,p in enumerate(plurals):
                    plural_keys[str(n)] = p.string

                self.assertEqual(entry.msgstr_plural, plural_keys)

            else:
                trans = se.get_translation(
                    self.resource.source_language.code, rule=5
                )

                self.assertEqual(entry.msgstr, trans.string.encode('utf-8'), "Source '%s'"\
                    " differs from translation %s" % (entry.msgstr,
                    trans.string.encode('utf-8')))
开发者ID:hfeeki,项目名称:transifex,代码行数:56,代码来源:__init__.py

示例4: test_headers_on_pot

# 需要导入模块: from transifex.resources.formats.pofile import POHandler [as 别名]
# 或者: from transifex.resources.formats.pofile.POHandler import compile [as 别名]
 def test_headers_on_pot(self):
     handler = POHandler(os.path.join(
             os.path.dirname(__file__), 'tests.pot')
     )
     handler.bind_resource(self.resource)
     handler.set_language(self.resource.source_language)
     handler.parse_file(is_source=True)
     handler.save2db(is_source=True)
     handler.compile()
     self.assertFalse("FIRST AUTHOR" in handler.compiled_template)
     handler.compile_pot()
     self.assertTrue("FIRST AUTHOR" in handler.compiled_template)
开发者ID:hfeeki,项目名称:transifex,代码行数:14,代码来源:__init__.py


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