def convertodf(inputfile, outputfile, templates): """reads in stdin using fromfileclass, converts using convertorclass, writes to stdout """ @contextmanager def store_context(): store = factory.getobject(outputfile) try: store.setfilename(store.getfilenode('NoName'), inputfile.name) except: print("couldn't set origin filename") yield store store.save() # Since the convertoptionsparser will give us an open file, we risk that # it could have been opened in non-binary mode on Windows, and then we'll # have problems, so let's make sure we have what we want. inputfile.close() inputfile = file(inputfile.name, mode='rb') with store_context() as store: contents = odf_io.open_odf(inputfile) for data in contents.values(): parse_state = extract.ParseState(odf_shared.no_translate_content_elements, odf_shared.inline_elements) extract.build_store(StringIO(data), store, parse_state) return True
def convertfile(storefile): store = xlifffile() store.setfilename(store.getfilenode("NoName"), "odf") contents = open_odf(storefile) for data in contents.values(): parse_state = ParseState(no_translate_content_elements, inline_elements) build_store(BytesIO(data), store, parse_state) return store
def translate_toolkit_implementation(store): from translate.storage.xml_extract import extract from translate.storage import odf_shared contents = odf_io.open_odf(inputfile) for data in contents.values(): parse_state = extract.ParseState(odf_shared.no_translate_content_elements, odf_shared.inline_elements) extract.build_store(StringIO(data), store, parse_state)
def convertodf(inputfile, outputfile, templates): """Convert an ODF package to XLIFF.""" store = factory.getobject(outputfile) try: store.setfilename(store.getfilenode('NoName'), inputfile.name) except Exception: print("couldn't set origin filename") contents = open_odf(inputfile) for data in contents.values(): parse_state = ParseState(no_translate_content_elements, inline_elements) build_store(BytesIO(data), store, parse_state) store.save() return True
def convertodf(inputfile, outputfile, templates): """Convert an ODF package to XLIFF.""" # Since the convertoptionsparser will give us an open file, we risk that # it could have been opened in non-binary mode on Windows, and then we'll # have problems, so let's make sure we have what we want. inputfile.close() inputfile = file(inputfile.name, mode='rb') store = factory.getobject(outputfile) try: store.setfilename(store.getfilenode('NoName'), inputfile.name) except: print("couldn't set origin filename") contents = open_odf(inputfile) for data in contents.values(): parse_state = ParseState(no_translate_content_elements, inline_elements) build_store(StringIO(data), store, parse_state) store.save() return True
def convertodf(inputfile, outputfile, templates): """Convert an ODF package to XLIFF.""" # Since the convertoptionsparser will give us an open file, we risk that # it could have been opened in non-binary mode on Windows, and then we'll # have problems, so let's make sure we have what we want. inputfile.close() inputfile = file(inputfile.name, mode='rb') store = factory.getobject(outputfile) try: store.setfilename(store.getfilenode('NoName'), inputfile.name) except: print("couldn't set origin filename") contents = open_odf(inputfile) for data in contents.values(): parse_state = ParseState(no_translate_content_elements, inline_elements) build_store(BytesIO(data), store, parse_state) store.save() return True