def xliff_import(self, howmuch, 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 """ try: data = file.read() xliff = XLIFF(string=data) except: return MessageDialog( title="Parse error", message=_("impossible to parse the file"), action="manage_Import_form" ) num_notes = 0 num_trans = 0 (file_ids, sources, targets) = xliff.get_languages() if howmuch == "clear": # Clear the message catalogue prior to import self._messages = {} self._languages = () self._default_language = sources[0] # update languages if len(sources) > 1 or sources[0] != self._default_language: return MessageDialog( title="Language error", message=_("incompatible language sources"), action="manage_Import_form" ) for lang in targets: if lang != self._default_language and lang not in self._languages: self._languages += (lang,) # get messages for file in xliff.state.files: cur_target = file.attributes.get("target-language", "") for msg in file.body.keys(): if not self._messages.has_key(msg) and howmuch == "existing": pass else: if not self._messages.has_key(msg): self._messages[msg] = {} if cur_target and file.body[msg].target: self._messages[msg][cur_target] = file.body[msg].target num_trans += 1 if file.body[msg].notes: ns = [n.text for n in file.body[msg].notes] comment = " ".join(ns) self._messages[msg]["note"] = comment num_notes += 1 if REQUEST is not None: return MessageDialog( title=_(u"Messages imported"), message=(_(u"Imported %d messages and %d notes to %s") % (num_trans, num_notes, " ".join(targets))), 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 """ try: data = file.read() xliff = XLIFF(string=data) except: return MessageDialog(title = 'Parse error', message = _('impossible to parse the file') , action = 'manage_import',) num_trans = 0 (file_ids, sources, targets) = xliff.get_languages() # update languages if len(sources) > 1 or sources[0] != self._default_language: return MessageDialog(title = 'Language error', message = _('incompatible language sources') , action = 'manage_import',) for lang in targets: if lang != self._default_language and lang not in self._languages: self._languages += (lang,) # get messages for file in xliff.state.files: cur_target = file.attributes.get('target-language', '') for msg in file.body.keys(): for (prop, val) in self._local_properties.items(): if val[self._default_language][0] == msg: if cur_target and file.body[msg].target: texte = file.body[msg].target self.set_localpropvalue(prop, cur_target, texte) num_trans += 1 if REQUEST is not None: return MessageDialog( title = _(u'Messages imported'), message = (_(u'Imported %d messages to %s') % (num_trans, ' '.join(targets))), action = 'manage_localPropertiesForm')