本文整理汇总了Python中babel.messages.Catalog.update方法的典型用法代码示例。如果您正苦于以下问题:Python Catalog.update方法的具体用法?Python Catalog.update怎么用?Python Catalog.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.messages.Catalog
的用法示例。
在下文中一共展示了Catalog.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _update
# 需要导入模块: from babel.messages import Catalog [as 别名]
# 或者: from babel.messages.Catalog import update [as 别名]
def _update(self, app, template_catalog, langs):
if template_catalog is None:
with open(_get_pot_path(app)) as infp:
template_catalog = pofile.read_po(infp, charset="utf8")
for lang in langs:
po_path = _get_po_path(app, language=lang)
if os.path.isfile(po_path):
with open(po_path) as infp:
lang_catalog = pofile.read_po(infp, charset="utf8")
else:
lang_catalog = Catalog(locale=lang, charset="utf8")
lang_catalog.update(template_catalog)
if len(lang_catalog):
with open(po_path, "w") as outf:
pofile.write_po(outf, lang_catalog, width=1000, omit_header=True, sort_output=True)
self.log.info("%s: updated %s", app.label, po_path)
示例2: _update
# 需要导入模块: from babel.messages import Catalog [as 别名]
# 或者: from babel.messages.Catalog import update [as 别名]
def _update(self, app, template_catalog, langs):
if template_catalog is None:
with open(self._get_pot_path(app)) as infp:
template_catalog = pofile.read_po(infp, charset="utf8")
for lang in langs:
po_path = self._get_po_path(app, language=lang)
if os.path.isfile(po_path):
with open(po_path) as infp:
lang_catalog = pofile.read_po(infp, charset="utf8")
else:
# When running on a version of Babel without proper locale data, pretend we don't even want
# to create a locale-bound catalog. Baka Babel.
lang_catalog = Catalog(locale=(lang if _babel_has_locale_data() else None), charset="utf8")
lang_catalog.update(template_catalog)
if len(lang_catalog):
with open(po_path, "w") as outf:
pofile.write_po(outf, lang_catalog, width=1000, omit_header=True, sort_output=True)
self.log.info("%s: updated %s", app.label, po_path)