def convertoo(inputfile, outputfile, templates, pot=False, sourcelanguage=None, targetlanguage=None, duplicatestyle="msgctxt", multifilestyle="single"): """reads in stdin using inputstore class, converts using convertorclass, writes to stdout""" inputstore = oo.oofile() if hasattr(inputfile, "filename"): inputfilename = inputfile.filename else: inputfilename = "(input file name not known)" inputstore.filename = inputfilename inputstore.parse(inputfile.read()) if not sourcelanguage: testlangtype = targetlanguage or (inputstore and inputstore.languages[0]) or "" if testlangtype.isdigit(): sourcelanguage = "01" else: sourcelanguage = "en-US" if not sourcelanguage in inputstore.languages: logger.warning("sourcelanguage '%s' not found in inputfile '%s' " "(contains %s)", sourcelanguage, inputfilename, ", ".join(inputstore.languages)) if not pot and (targetlanguage and targetlanguage not in inputstore.languages): logger.warning("targetlanguage '%s' not found in inputfile '%s' " "(contains %s)", targetlanguage, inputfilename, ", ".join(inputstore.languages)) convertor = oo2xliff(sourcelanguage, targetlanguage, blankmsgstr=pot, long_keys=(multifilestyle != "single")) outputstore = convertor.convertstore(inputstore, duplicatestyle) if outputstore.isempty(): return 0 outputfile.write(str(outputstore)) return 1
def convertoo(inputfile, outputfile, templates, pot=False, sourcelanguage=None, targetlanguage=None, duplicatestyle="msgid_comment", multifilestyle="single"): """reads in stdin using inputstore class, converts using convertorclass, writes to stdout""" inputstore = oo.oofile() if hasattr(inputfile, "filename"): inputfilename = inputfile.filename else: inputfilename = "(input file name not known)" inputstore.filename = inputfilename inputstore.parse(inputfile.read()) if not sourcelanguage: testlangtype = targetlanguage or (inputstore and inputstore.languages[0]) or "" if testlangtype.isdigit(): sourcelanguage = "01" else: sourcelanguage = "en-US" if sourcelanguage not in inputstore.languages: logger.warning("sourcelanguage '%s' not found in inputfile '%s' " "(contains %s)", sourcelanguage, inputfilename, ", ".join(inputstore.languages)) if targetlanguage and targetlanguage not in inputstore.languages: logger.warning("targetlanguage '%s' not found in inputfile '%s' " "(contains %s)", targetlanguage, inputfilename, ", ".join(inputstore.languages)) convertor = oo2po(sourcelanguage, targetlanguage, blankmsgstr=pot, long_keys=multifilestyle != "single") outputstore = convertor.convertstore(inputstore, duplicatestyle) if outputstore.isempty(): return 0 outputstore.serialize(outputfile) return 1
def test_preserve_filename(self): """Ensures that the filename is preserved.""" oosource = br'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58' self.create_testfile("snippet.sdf", oosource) oofile = oo.oofile(self.open_testfile("snippet.sdf")) assert oofile.filename.endswith("snippet.sdf") oofile.parse(oosource) assert oofile.filename.endswith("snippet.sdf")
def test_preserve_filename(self): """Ensures that the filename is preserved.""" oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58' self.create_testfile("snippet.sdf", oosource) oofile = oo.oofile(self.open_testfile("snippet.sdf")) assert oofile.filename.endswith("snippet.sdf") oofile.parse(oosource) assert oofile.filename.endswith("snippet.sdf")
def convert(self, oosource, sourcelanguage='en-US', targetlanguage='af-ZA'): """helper that converts oo source to po source without requiring files""" if isinstance(oosource, six.text_type): oosource = oosource.encode('utf-8') inputoo = oo.oofile(oosource) convertor = self.conversion_class(sourcelanguage, targetlanguage) outputpo = convertor.convertstore(inputoo) return outputpo
def convert(self, oosource, sourcelanguage='en-US', targetlanguage='af-ZA'): """helper that converts oo source to po source without requiring files""" inputoo = oo.oofile(oosource) convertor = self.conversion_class(sourcelanguage, targetlanguage) outputpo = convertor.convertstore(inputoo) return outputpo
def convert(self, oosource, sourcelanguage="en-US", targetlanguage="af-ZA"): """helper that converts oo source to po source without requiring files""" if isinstance(oosource, str): oosource = oosource.encode("utf-8") inputoo = oo.oofile(oosource) convertor = self.conversion_class(sourcelanguage, targetlanguage) outputpo = convertor.convertstore(inputoo) return outputpo
def convertoo( inputfile, outputfile, templates, pot=False, sourcelanguage=None, targetlanguage=None, duplicatestyle="msgid_comment", multifilestyle="single", ): """reads in stdin using inputstore class, converts using convertorclass, writes to stdout""" inputstore = oo.oofile() if hasattr(inputfile, "filename"): inputfilename = inputfile.filename else: inputfilename = "(input file name not known)" inputstore.filename = inputfilename inputstore.parse(inputfile.read()) if not sourcelanguage: testlangtype = targetlanguage or (inputstore and inputstore.languages[0]) or "" if testlangtype.isdigit(): sourcelanguage = "01" else: sourcelanguage = "en-US" if not sourcelanguage in inputstore.languages: print >>sys.stderr, "Warning: sourcelanguage '%s' not found in inputfile '%s' (contains %s)" % ( sourcelanguage, inputfilename, ", ".join(inputstore.languages), ) if targetlanguage and targetlanguage not in inputstore.languages: print >>sys.stderr, "Warning: targetlanguage '%s' not found in inputfile '%s' (contains %s)" % ( targetlanguage, inputfilename, ", ".join(inputstore.languages), ) convertor = oo2po(sourcelanguage, targetlanguage, blankmsgstr=pot, long_keys=multifilestyle != "single") outputstore = convertor.convertstore(inputstore, duplicatestyle) if outputstore.isempty(): return 0 outputfile.write(str(outputstore)) return 1
def convertoo(inputfile, outputfile, templates, pot=False, sourcelanguage=None, targetlanguage=None, duplicatestyle="msgctxt", multifilestyle="single"): """reads in stdin using inputstore class, converts using convertorclass, writes to stdout""" inputstore = oo.oofile() if hasattr(inputfile, "filename"): inputfilename = inputfile.filename else: inputfilename = "(input file name not known)" inputstore.filename = inputfilename inputstore.parse(inputfile.read()) if not sourcelanguage: testlangtype = targetlanguage or (inputstore and inputstore.languages[0]) or "" if testlangtype.isdigit(): sourcelanguage = "01" else: sourcelanguage = "en-US" if not sourcelanguage in inputstore.languages: print >> sys.stderr, "Warning: sourcelanguage '%s' not found in inputfile '%s' (contains %s)" % ( sourcelanguage, inputfilename, ", ".join(inputstore.languages)) if not pot and targetlanguage and targetlanguage not in inputstore.languages: print >> sys.stderr, "Warning: targetlanguage '%s' not found in inputfile '%s' (contains %s)" % ( targetlanguage, inputfilename, ", ".join(inputstore.languages)) convertor = oo2xliff(sourcelanguage, targetlanguage, blankmsgstr=pot, long_keys=multifilestyle != "single") outputstore = convertor.convertstore(inputstore, duplicatestyle) if outputstore.isempty(): return 0 outputfile.write(str(outputstore)) return 1
def readoo(self, of): """read in the oo from the file""" oosrc = of.read() self.o = oo.oofile() self.o.parse(oosrc) self.makeindex()
def ooparse(self, oosource): """helper that parses oo source without requiring files""" dummyfile = wStringIO.StringIO(oosource) oofile = oo.oofile(dummyfile) return oofile
def ooparse(self, oosource): """helper that parses oo source without requiring files""" dummyfile = BytesIO(oosource.encode()) oofile = oo.oofile(dummyfile) return oofile