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
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
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
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
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 = u"" 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) outputstore.serialize(outputfile) return 1
def merge2dtd(dtdsource, posource): """helper that merges po translations to dtd source without requiring files""" inputfile = BytesIO(posource.encode()) inputpo = po.pofile(inputfile) templatefile = BytesIO(dtdsource.encode()) templatedtd = dtd.dtdfile(templatefile) convertor = po2dtd.redtd(templatedtd) return convertor.convertstore(inputpo)
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)
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
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
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
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
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(): dtdunit = self.convertunit(inputunit) if dtdunit is not None: outputstore.addunit(dtdunit) return outputstore
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
def dtdparse(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. """ if not isinstance(dtdsource, bytes): dtdsource = dtdsource.encode("utf-8") dummyfile = BytesIO(dtdsource) return dtd.dtdfile(dummyfile, android=True)
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. """ if not isinstance(dtdsource, bytes): dtdsource = dtdsource.encode('utf-8') dummyfile = BytesIO(dtdsource) dtdfile = dtd.dtdfile(dummyfile, android=True) return dtdfile
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
def dtdparse(self, dtdsource): """helper that parses dtd source without requiring files""" dummyfile = wStringIO.StringIO(dtdsource) dtdfile = dtd.dtdfile(dummyfile) return dtdfile