def xliff_import(self, file, REQUEST=None): """ XLIFF is the XML Localization Interchange File Format designed by a group of software providers. It is specified by www.oasis-open.org """ messages = self._messages # Build a table of messages hashed on the md5 sum of the message # This is because sometimes the xliff file has the sources translated, # not the targets md5hash = {} for mes in messages.keys(): hash = md5text(mes) md5hash[hash] = mes parser = HandleXliffParsing() # parse the xliff information chandler = parser.parseXLIFFFile(file) if chandler is None: return MessageDialog(title = 'Parse error', message = 'Unable to parse XLIFF file' , action = 'manage_main',) header_info = chandler.getFileTag() #get the target language lang = [x for x in header_info if x[0]=='target-language'][0][1] (targetlang, core_lang) = self._normalize_lang(lang) # return a dictionary {id: (source, target)} body_info = chandler.getBody() num_notes = 0 num_translations = 0 # load the data for msgkey, transunit in body_info.items(): # If message is not in catalog, then it is new in xliff file # -- not legal if md5hash.has_key(msgkey): # Normal add srcmsg = md5hash[msgkey] if transunit['note'] != messages[srcmsg].get('note',u''): messages[srcmsg]['note'] = transunit['note'] num_notes = num_notes + 1 if srcmsg == transunit['target']: # No translation was done continue num_translations = num_translations + 1 if transunit['target'] == u'' and transunit['source'] != srcmsg: # The source was translated. Happens sometimes messages[srcmsg][targetlang] = transunit['source'] else: messages[srcmsg][targetlang] = transunit['target'] if REQUEST is not None: return MessageDialog(title = _('Messages imported'), message = _('Imported %d messages and %d notes to %s') % \ (num_translations, num_notes, targetlang) , action = 'manage_messages',)
def xliff_import(self, file, REQUEST=None): """ XLIFF is the XML Localization Interchange File Format designed by a group of software providers. It is specified by www.oasis-open.org """ messages = self._local_properties parser = HandleXliffParsing() #parse the xliff information chandler = parser.parseXLIFFFile(file) if chandler is None: return MessageDialog(title = 'Parse error', message = 'Unable to parse XLIFF file' , action = 'manage_main',) header_info = chandler.getFileTag() #get the target language lang = [x for x in header_info if x[0]=='target-language'][0][1] (targetlang, core_lang) = self._normalize_lang(lang) body_info = chandler.getBody() num_notes = 0 num_translations = 0 #load the data for k, v in body_info.items(): # If message is not in catalog, then it is new in xliff file -- not legal if messages.has_key(k): num_translations = num_translations + 1 if v['target'] == u'' and v['source'] != srcmsg: # The source was translated. Happens sometimes messages[k][targetlang] = v['source'] else: messages[k][targetlang] = v['target'] if REQUEST is not None: return MessageDialog( title = _(u'Messages imported'), message = (_(u'Imported %d messages and %d notes to %s') % (num_translations, num_notes, targetlang)), action = 'manage_localPropertiesForm')