本文整理汇总了Python中babel.messages.pofile.write_po方法的典型用法代码示例。如果您正苦于以下问题:Python pofile.write_po方法的具体用法?Python pofile.write_po怎么用?Python pofile.write_po使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.messages.pofile
的用法示例。
在下文中一共展示了pofile.write_po方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def main():
try:
import jieba # noqa: F401
except ImportError:
return
pofile.normalize = _normalize
for root, dirs, files in os.walk('.'):
if 'zh' not in root:
continue
for f in files:
if not f.endswith('.po'):
continue
path = os.path.join(root, f)
# only modify recent-changed files
modify_time = datetime.datetime.fromtimestamp(os.path.getmtime(path))
if (datetime.datetime.now() - modify_time).total_seconds() > 120:
continue
with open(path, 'rb') as inpf:
catalog = pofile.read_po(inpf)
with open(path, 'wb') as outf:
pofile.write_po(outf, catalog)
示例2: run
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def run(self):
log.info('creating catalog %r based on %r', self.output_file,
self.input_file)
infile = open(self.input_file, 'r')
try:
# Although reading from the catalog template, read_po must be fed
# the locale in order to correctly calculate plurals
catalog = read_po(infile, locale=self.locale)
finally:
infile.close()
catalog.locale = self._locale
catalog.revision_date = datetime.now(LOCALTZ)
catalog.fuzzy = False
outfile = open(self.output_file, 'wb')
try:
write_po(outfile, catalog, width=self.width)
finally:
outfile.close()
示例3: merge
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def merge(source, target_filename):
"""Merges the messages from the source Catalog into a .po file at
target_filename. Creates the target file if it doesn't exist."""
if os.path.exists(target_filename):
target = pofile.read_po(open(target_filename))
for message in source:
if message.id and message.string and not message.fuzzy:
log_change(message.id in target and target[message.id], message)
# This doesn't actually replace the message! It just updates
# the fields other than the string. See Catalog.__setitem__.
target[message.id] = message
# We have to mutate the message to update the string and flags.
target[message.id].string = message.string
target[message.id].flags = message.flags
else:
for message in source:
log_change(None, message)
target = source
target_file = create_file(target_filename)
pofile.write_po(target_file, target,
no_location=True, sort_output=True, ignore_obsolete=True)
target_file.close()
示例4: validate_pofile
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def validate_pofile(path: str) -> None:
with open(path, mode='rb+') as f:
catalog = pofile.read_po(f)
messages = list(catalog)
for message in messages:
if message.id and message.string:
validate_string(message, catalog)
f.seek(0)
f.truncate()
pofile.write_po(f, catalog)
示例5: dump_po
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def dump_po(filename, catalog, line_width=76):
"""write po/pot file from catalog object
:param unicode filename: path to po file
:param catalog: catalog object
:param line_width: maximum line wdith of po files
:return: None
"""
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
# Because babel automatically encode strings, file should be open as binary mode.
with io.open(filename, 'wb') as f:
pofile.write_po(f, catalog, line_width)
示例6: write_clean_po
# 需要导入模块: from babel.messages import pofile [as 别名]
# 或者: from babel.messages.pofile import write_po [as 别名]
def write_clean_po(filename, catalog):
"""Writes out a .po file in a canonical way, to minimize spurious diffs."""
catalog.creation_date = datetime.datetime(2000, 1, 1, 0, 0, 0)
file = open(filename, 'w')
pofile.write_po(file, catalog,
no_location=True, sort_output=True, ignore_obsolete=True)
file.close()