def lang2po(self, source): """helper that converts .lang source to po source without requiring files""" inputfile = wStringIO.StringIO(source) inputlang = lang.LangStore(inputfile) convertor = mozlang2po.lang2po() outputpo = convertor.convertstore(inputlang) return outputpo
def convertlang(inputfile, outputfile, templates, duplicatestyle="msgctxt", encoding="utf-8"): """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout""" inputstore = lang.LangStore(inputfile, encoding=encoding) convertor = lang2po(duplicatestyle=duplicatestyle) outputstore = convertor.convertstore(inputstore) if outputstore.isempty(): return 0 outputfile.write(str(outputstore)) return 1
def convertstore(self, inputstore, includefuzzy=False): """converts a file to .lang format""" thetargetfile = lang.LangStore() # Run over the po units for pounit in inputstore.units: # Skip the header if pounit.isheader(): continue newunit = thetargetfile.addsourceunit(pounit.source) if includefuzzy or not pounit.isfuzzy(): newunit.settarget(pounit.target) else: newunit.settarget(pounit.source) return thetargetfile
def convertstore(self, inputstore, includefuzzy=False): """converts a file to .lang format""" thetargetfile = lang.LangStore() # Run over the po units for pounit in inputstore.units: if pounit.isheader() or not pounit.istranslatable(): continue newunit = thetargetfile.addsourceunit(pounit.source) if includefuzzy or not pounit.isfuzzy(): newunit.settarget(pounit.target) else: newunit.settarget(pounit.source) if pounit.getnotes('developer'): newunit.addnote(pounit.getnotes('developer'), 'developer') return thetargetfile