def l20n2po(self, l20n_source, l20n_template=None): """helper that converts .ftl (l20n) source to po source without requiring files""" inputfile = wStringIO.StringIO(l20n_source) input_l20n = l20n.l20nfile(inputfile) convertor = l20n2po.l20n2po() if l20n_template: templatefile = wStringIO.StringIO(l20n_template) template_l20n = l20n.l20nfile(templatefile) outputpo = convertor.merge_stores(template_l20n, input_l20n) else: outputpo = convertor.convert_store(input_l20n) return outputpo
def convertl20n(inputfile, outputfile, templatefile, pot=False, duplicatestyle="msgctxt"): inputstore = l20n.l20nfile(inputfile) convertor = l20n2po(blankmsgstr=pot, duplicatestyle=duplicatestyle) if templatefile is None: outputstore = convertor.convert_store(inputstore) else: templatestore = l20n.l20nfile(templatefile) outputstore = convertor.merge_stores(templatestore, inputstore) if outputstore.isempty(): return 0 outputstore.serialize(outputfile) return 1
def __init__(self, inputfile, outputfile, templatefile=None, includefuzzy=False, outputthreshold=None): if templatefile is None: raise ValueError("must have template file for ftl files") self.inputstore = po.pofile(inputfile) self.outputfile = outputfile self.template_store = l20n.l20nfile(templatefile) self.includefuzzy = includefuzzy self.outputthreshold = outputthreshold
def convert_store(self): outputstore = l20n.l20nfile() self.inputstore.makeindex() for l20nunit in self.template_store.units: l20nunit_id = l20nunit.getid() if l20nunit_id in self.inputstore.locationindex: po_unit = self.inputstore.locationindex[l20nunit_id] newunit = self.convert_unit(po_unit) outputstore.addunit(newunit) return outputstore
def l20n_parse(self, l20n_source): """helper that parses l20n source without requiring files""" dummyfile = wStringIO.StringIO(l20n_source) l20n_file = l20n.l20nfile(dummyfile) return l20n_file
def l20n_parse(self, l20n_source): """helper that parses l20n source without requiring files""" dummyfile = BytesIO(l20n_source.encode()) l20n_file = l20n.l20nfile(dummyfile) return l20n_file