def itools_implementation(store): from itools.handlers import get_handler from itools.gettext.po import encode_source import itools.odf filename = getattr(inputfile, 'name', 'unkown') handler = get_handler(filename) try: get_units = handler.get_units except AttributeError: raise AttributeError('error: the file "%s" could not be processed' % filename) # Make the XLIFF file for source, context, line in get_units(): source = encode_source(source) unit = store.UnitClass(source) store.addunit(unit)
def ttk_odf2xliff_handler(filename): # Make the xliff file command = ['odf2xliff', filename, 'tmp.xlf'] # command = ['odf2xliff', '--engine=itools', filename, 'tmp.xlf'] process = Popen(command, stdout=PIPE, stderr=PIPE) if process.wait() != 0: raise ValueError, '"%s" is malformed' % filename # Get the units units = [] xlf_file = XLFFile('tmp.xlf') for a_file in xlf_file.files.values(): for unit in a_file.body.values(): unit = encode_source(unit.source) # unit = unit.strip(SPACE) # unit = collapse(unit) units.append(unit) # Remove the tmp file remove('tmp.xlf') return units
def itools_handler(filename): handler = get_handler(filename) units = handler.get_units(srx) return [ encode_source(unit) for unit, context, reference in units ]