本文整理汇总了Python中translate.storage.dtd.dtdfile函数的典型用法代码示例。如果您正苦于以下问题:Python dtdfile函数的具体用法?Python dtdfile怎么用?Python dtdfile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dtdfile函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dtd2po
def dtd2po(self, dtdsource, dtdtemplate=None):
"""helper that converts dtd source to po source without requiring files"""
inputfile = wStringIO.StringIO(dtdsource)
inputdtd = dtd.dtdfile(inputfile)
convertor = dtd2po.dtd2po()
if dtdtemplate is None:
outputpo = convertor.convertstore(inputdtd)
else:
templatefile = wStringIO.StringIO(dtdtemplate)
templatedtd = dtd.dtdfile(templatefile)
outputpo = convertor.mergestore(templatedtd, inputdtd)
return outputpo
示例2: convertdtd
def convertdtd(inputfile, outputfile, templatefile, pot=False, duplicatestyle="msgctxt"):
"""reads in inputfile and templatefile using dtd, converts using dtd2po, writes to outputfile"""
inputstore = dtd.dtdfile(inputfile)
convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
if templatefile is None:
outputstore = convertor.convertstore(inputstore)
else:
templatestore = dtd.dtdfile(templatefile)
outputstore = convertor.mergestore(templatestore, inputstore)
if outputstore.isempty():
return 0
outputfile.write(str(outputstore))
return 1
示例3: dtdparse
def dtdparse(self, dtdsource):
"""helper that parses dtd source without requiring files"""
if not isinstance(dtdsource, bytes):
dtdsource = dtdsource.encode('utf-8')
dummyfile = BytesIO(dtdsource)
dtdfile = dtd.dtdfile(dummyfile)
return dtdfile
示例4: convertdtd
def convertdtd(inputfile, outputfile, templatefile, includefuzzy=False,
remove_untranslated=False, outputthreshold=None):
inputstore = po.pofile(inputfile)
if not convert.should_output_store(inputstore, outputthreshold):
return False
# Some of the DTD files used for Firefox Mobile are actually completely
# different with different escaping and quoting rules. The best way to
# identify them seems to be on their file path in the tree (based on code
# in compare-locales).
android_dtd = False
header_comment = ""
input_header = inputstore.header()
if input_header:
header_comment = input_header.getnotes("developer")
if "embedding/android" in header_comment or "mobile/android/base" in header_comment:
android_dtd = True
if templatefile is None:
convertor = po2dtd(android=android_dtd,
remove_untranslated=remove_untranslated)
else:
templatestore = dtd.dtdfile(templatefile, android=android_dtd)
convertor = redtd(templatestore, android=android_dtd,
remove_untranslated=remove_untranslated)
outputstore = convertor.convertstore(inputstore, includefuzzy)
outputfile.write(str(outputstore))
return 1
示例5: merge2dtd
def merge2dtd(self, dtdsource, posource):
"""helper that merges po translations to dtd source without requiring files"""
inputfile = wStringIO.StringIO(posource)
inputpo = po.pofile(inputfile)
templatefile = wStringIO.StringIO(dtdsource)
templatedtd = dtd.dtdfile(templatefile)
convertor = po2dtd.redtd(templatedtd)
outputdtd = convertor.convertstore(inputpo)
return outputdtd
示例6: convertstore
def convertstore(self, inputstore, includefuzzy=False):
outputstore = dtd.dtdfile()
self.currentgroups = []
for inputunit in inputstore.units:
if includefuzzy or not inputunit.isfuzzy():
dtdunit = self.convertunit(inputunit)
if dtdunit is not None:
outputstore.addunit(dtdunit)
return outputstore
示例7: dtdparse
def dtdparse(self, dtdsource):
"""Parses an Android DTD source string and returns a DTD store.
This allows to simulate reading from Android DTD files without really
having real Android DTD files.
"""
dummyfile = wStringIO.StringIO(dtdsource)
dtdfile = dtd.dtdfile(dummyfile, android=True)
return dtdfile
示例8: openDTD
def openDTD(file):
f = open(file, "r")
dtdobj = dtd.dtdfile(f)
f.close()
dtdentries = dtdobj.units
d = OrderedDict()
for i in dtdentries:
if d.has_key(i.entity): print "Duplicate entry: %s" %i.entity
else: d[i.entity] = dtd.unquotefromdtd(i.definition)
示例9: convertstore
def convertstore(self, inputstore, includefuzzy=False):
outputstore = dtd.dtdfile(android=self.android)
self.currentgroups = []
for inputunit in inputstore.units:
if (includefuzzy or not inputunit.isfuzzy()) and (inputunit.istranslated() or not self.remove_untranslated):
dtdunit = self.convertunit(inputunit)
if dtdunit is not None:
outputstore.addunit(dtdunit)
return outputstore
示例10: convertdtd
def convertdtd(inputfile, outputfile, templatefile, includefuzzy=False):
inputstore = po.pofile(inputfile)
if templatefile is None:
convertor = po2dtd()
else:
templatestore = dtd.dtdfile(templatefile)
convertor = redtd(templatestore)
outputstore = convertor.convertstore(inputstore, includefuzzy)
outputfile.write(str(outputstore))
return 1
示例11: convertdtd
def convertdtd(inputfile, outputfile, templatefile, pot=False,
duplicatestyle="msgctxt"):
"""reads in inputfile and templatefile using dtd, converts using dtd2po,
writes to outputfile"""
android_dtd = False
if hasattr(inputfile, "name"):
# Check if it is an Android DTD file.
if ("embedding/android" in inputfile.name or
"mobile/android/base" in inputfile.name):
android_dtd = True
inputstore = dtd.dtdfile(inputfile, android=android_dtd)
convertor = dtd2po(blankmsgstr=pot, duplicatestyle=duplicatestyle)
if templatefile is None:
outputstore = convertor.convertstore(inputstore)
else:
templatestore = dtd.dtdfile(templatefile, android=android_dtd)
outputstore = convertor.mergestore(templatestore, inputstore)
if outputstore.isempty():
return 0
outputfile.write(str(outputstore))
return 1