本文整理匯總了Python中polib.POFile方法的典型用法代碼示例。如果您正苦於以下問題:Python polib.POFile方法的具體用法?Python polib.POFile怎麽用?Python polib.POFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類polib
的用法示例。
在下文中一共展示了polib.POFile方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_strings_to_translate
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [as 別名]
def get_strings_to_translate(self, po):
"""Return list of string to translate from po file.
:param po: POFile object to translate
:type po: polib.POFile
:return: list of string to translate
:rtype: collections.Iterable[six.text_type]
"""
strings = []
for index, entry in enumerate(po):
if not self.need_translate(entry):
continue
strings.append(humanize_placeholders(entry.msgid))
if entry.msgid_plural:
strings.append(humanize_placeholders(entry.msgid_plural))
return strings
示例2: __init__
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [as 別名]
def __init__(self, target, modules, lang):
import odoo.release as release
self.buffer = target
self.lang = lang
self.po = polib.POFile()
self.po.header = "Translation of %s.\n" \
"This file contains the translation of the following modules:\n" \
"%s" % (release.description, ''.join("\t* %s\n" % m for m in modules))
now = datetime.utcnow().strftime('%Y-%m-%d %H:%M+0000')
self.po.metadata = {
'Project-Id-Version': "%s %s" % (release.description, release.version),
'Report-Msgid-Bugs-To': '',
'POT-Creation-Date': now,
'PO-Revision-Date': now,
'Last-Translator': '',
'Language-Team': '',
'MIME-Version': '1.0',
'Content-Type': 'text/plain; charset=UTF-8',
'Content-Transfer-Encoding': '',
'Plural-Forms': '',
}
示例3: pofile_from_entry
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [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)
示例4: test_ok
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [as 別名]
def test_ok(self):
# what lt's Plural-Forms is supposed to look like
poobj = polib.POFile()
poobj.metadata["Plural-Forms"] = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2)\n"
with pofile(poobj) as p:
test_usability(p.name)
示例5: test_busted_plural_forms
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [as 別名]
def test_busted_plural_forms(self):
# https://bugzilla.redhat.com/show_bug.cgi?id=1283599
poobj = polib.POFile()
poobj.metadata["Plural-Forms"] = "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 or n%100>=20) ? 1 : 2)\n"
with pofile(poobj) as p:
self.assertRaises(Exception, test_usability, p.name)
示例6: test_success
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [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))
示例7: test_some_failure
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [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))
示例8: update_translations
# 需要導入模塊: import polib [as 別名]
# 或者: from polib import POFile [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')