當前位置: 首頁>>代碼示例>>Python>>正文


Python polib.POEntry方法代碼示例

本文整理匯總了Python中polib.POEntry方法的典型用法代碼示例。如果您正苦於以下問題:Python polib.POEntry方法的具體用法?Python polib.POEntry怎麽用?Python polib.POEntry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在polib的用法示例。


在下文中一共展示了polib.POEntry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testString

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def testString(poentry):
    """Run all tests against the given translatable string.

       :param polib.POEntry poentry: The PO file entry to test
       :returns: whether the tests succeeded or not
       :rtype: bool
    """
    success = True
    for test in _tests:
        try:
            test(poentry)
        except Exception as e: # pylint: disable=broad-except
            success = False
            print("%s failed on %s: %s" % (test.__name__, poentry.msgid, str(e)))

    return success 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:18,代碼來源:__init__.py

示例2: convert_msg

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def convert_msg(self, msg):
        """
        Takes one POEntry object and converts it (adds a dummy translation to it)
        msg is an instance of polib.POEntry
        """
        source = msg.msgid
        if not source:
            # don't translate empty string
            return

        plural = msg.msgid_plural
        if plural:
            # translate singular and plural
            foreign_single = self.convert(source)
            foreign_plural = self.convert(plural)
            plural = {
                '0': self.final_newline(source, foreign_single),
                '1': self.final_newline(plural, foreign_plural),
            }
            msg.msgstr_plural = plural
        else:
            foreign = self.convert(source)
            msg.msgstr = self.final_newline(source, foreign) 
開發者ID:edx,項目名稱:i18n-tools,代碼行數:25,代碼來源:dummy.py

示例3: add_entry

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def add_entry(self, modules, tnrs, source, trad, comments=None):
        entry = polib.POEntry(
            msgid=source,
            msgstr=trad,
        )
        plural = len(modules) > 1 and 's' or ''
        entry.comment = "module%s: %s" % (plural, ', '.join(modules))
        if comments:
            entry.comment += "\n" + "\n".join(comments)

        code = False
        for typy, name, res_id in tnrs:
            if typy == 'code':
                code = True
                res_id = 0
            if isinstance(res_id, int) or res_id.isdigit():
                # second term of occurrence must be a digit
                # occurrence line at 0 are discarded when rendered to string
                entry.occurrences.append((u"%s:%s" % (typy, name), str(res_id)))
            else:
                entry.occurrences.append((u"%s:%s:%s" % (typy, name, res_id), ''))
        if code:
            entry.flags.append("python-format")
        self.po.append(entry) 
開發者ID:guohuadeng,項目名稱:odoo13-x64,代碼行數:26,代碼來源:translate.py

示例4: pofile_from_entry

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def pofile_from_entry(*args, **kwargs):
    poobj = polib.POFile()
    poobj.metadata["Content-Type"] = "text/plain; charset=UTF-8"
    poobj.append(polib.POEntry(*args, **kwargs))
    return pofile(poobj) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:7,代碼來源:test_translated.py

示例5: test_ok

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_ok(self):
        # no markup
        test_markup(POEntry(msgid="test string"))

        # internal markup
        test_markup(POEntry(msgid="<b>test</b> string")) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:8,代碼來源:test_translatable.py

示例6: test_unnecessary_markup

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_unnecessary_markup(self):
        self.assertRaises(AssertionError, test_markup, POEntry(msgid="<b>test string</b>")) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:4,代碼來源:test_translatable.py

示例7: test_no_comment

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_no_comment(self):
        self.assertRaises(AssertionError, test_comment, POEntry(msgid="c"))

# Test the top-level functions
# fake tests for testing with 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:7,代碼來源:test_translatable.py

示例8: test_failure

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_failure(self):
        self.assertFalse(testString(POEntry())) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:4,代碼來源:test_translatable.py

示例9: test_success

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_success(self):
        with tempfile.NamedTemporaryFile(suffix=".pot") as potfile:
            poobj = POFile()
            poobj.append(POEntry(msgstr="test string"))
            poobj.save(potfile.name)

            self.assertTrue(testPOT(potfile.name)) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:9,代碼來源:test_translatable.py

示例10: test_some_failure

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_some_failure(self):
        with tempfile.NamedTemporaryFile(suffix=".pot") as potfile:
            poobj = POFile()
            poobj.append(POEntry(msgstr="test string"))
            poobj.append(POEntry(msgstr="pest string"))
            poobj.save(potfile.name)

            self.assertFalse(testPOT(potfile.name)) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:10,代碼來源:test_translatable.py

示例11: test_all_failure

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_all_failure(self):
        with tempfile.NamedTemporaryFile(suffix=".pot") as potfile:
            poobj = POFile()
            poobj.append(POEntry(msgstr="pest string"))
            poobj.append(POEntry(msgstr="past string"))
            poobj.save(potfile.name)

            self.assertFalse(testPOT(potfile.name)) 
開發者ID:storaged-project,項目名稱:libbytesize,代碼行數:10,代碼來源:test_translatable.py

示例12: update_translations

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def update_translations(self, entries, translated_strings):
        """Update translations in entries.

        The order and number of translations should match to get_strings_to_translate() result.

        :param entries: list of entries to translate
        :type entries: collections.Iterable[polib.POEntry] | polib.POFile
        :param translated_strings: list of translations
        :type translated_strings: collections.Iterable[six.text_type]
        """
        translations = iter(translated_strings)
        for entry in entries:
            if not self.need_translate(entry):
                continue

            if entry.msgid_plural:
                # fill the first plural form with the entry.msgid translation
                translation = next(translations)
                translation = fix_translation(entry.msgid, translation)
                entry.msgstr_plural[0] = translation

                # fill the rest of plural forms with the entry.msgid_plural translation
                translation = next(translations)
                translation = fix_translation(entry.msgid_plural, translation)
                for k, v in entry.msgstr_plural.items():
                    if k != 0:
                        entry.msgstr_plural[k] = translation
            else:
                translation = next(translations)
                translation = fix_translation(entry.msgid, translation)
                entry.msgstr = translation

            # Set the 'fuzzy' flag on translation
            if self.set_fuzzy and 'fuzzy' not in entry.flags:
                entry.flags.append('fuzzy') 
開發者ID:ankitpopli1891,項目名稱:django-autotranslate,代碼行數:37,代碼來源:translate_messages.py

示例13: test_is_keystring

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_is_keystring(self):
        """
        Verifies is_keystring predicate
        """
        entry1 = polib.POEntry()
        entry2 = polib.POEntry()
        entry1.msgid = "_.lms.admin.warning.keystring"
        entry2.msgid = "This is not a keystring"
        self.assertTrue(extract.is_key_string(entry1.msgid))
        self.assertFalse(extract.is_key_string(entry2.msgid)) 
開發者ID:edx,項目名稱:i18n-tools,代碼行數:12,代碼來源:test_extract.py

示例14: test_singular

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_singular(self):
        entry = POEntry()
        entry.msgid = "A lovely day for a cup of tea."
        expected = u"À lövélý däý för ä çüp öf téä. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢т#"
        self.converter.convert_msg(entry)
        self.assertUnicodeEquals(entry.msgstr, expected) 
開發者ID:edx,項目名稱:i18n-tools,代碼行數:8,代碼來源:test_dummy.py

示例15: test_plural

# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POEntry [as 別名]
def test_plural(self):
        entry = POEntry()
        entry.msgid = "A lovely day for a cup of tea."
        entry.msgid_plural = "A lovely day for some cups of tea."
        expected_s = u"À lövélý däý för ä çüp öf téä. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢т#"
        expected_p = u"À lövélý däý för sömé çüps öf téä. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєт#"
        self.converter.convert_msg(entry)
        result = entry.msgstr_plural
        self.assertUnicodeEquals(result['0'], expected_s)
        self.assertUnicodeEquals(result['1'], expected_p) 
開發者ID:edx,項目名稱:i18n-tools,代碼行數:12,代碼來源:test_dummy.py


注:本文中的polib.POEntry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。