Example #1
0
    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',)
Example #2
0
    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')
Example #3
0
textdoc.styles.addElement(tablecontents)

# tablestyle = style.Style(name="Table style", family="table")
# tablestyle.addElement(style.TableProperties(protected="true"))
# textdoc.automaticstyles.addElement(tablestyle)

# Create automatic styles for the column widths.
widthwide = style.Style(name="Wwide", family="table-column")
widthwide.addElement(style.TableColumnProperties(columnwidth="8cm"))
textdoc.automaticstyles.addElement(widthwide)

tcstyle = style.Style(name="Table Cell", family="table-cell")
tcstyle.addElement(style.TableCellProperties(cellprotect="protected"))
textdoc.automaticstyles.addElement(tcstyle)

parser = HandleXliffParsing()
xliff = file("global.xlf").read()
chandler = parser.parseXLIFFSTring(xliff)
if chandler is None:
    print "Unable to parse XLIFF file"
    sys.exit(0)

header_info = chandler.getFileTag()
body_info = chandler.getBody()  # return a dictionary

uf = UserFieldDecls()
textdoc.text.addElement(uf)

# Add user fields
for id, transunit in body_info.items():
    uf.addElement(UserFieldDecl(name=id, valuetype="string", stringvalue=transunit["target"]))
textdoc.styles.addElement(tablecontents)

#tablestyle = style.Style(name="Table style", family="table")
#tablestyle.addElement(style.TableProperties(protected="true"))
#textdoc.automaticstyles.addElement(tablestyle)

# Create automatic styles for the column widths.
widthwide = style.Style(name="Wwide", family="table-column")
widthwide.addElement(style.TableColumnProperties(columnwidth="8cm"))
textdoc.automaticstyles.addElement(widthwide)

tcstyle = style.Style(name="Table Cell", family="table-cell")
tcstyle.addElement(style.TableCellProperties(cellprotect="protected"))
textdoc.automaticstyles.addElement(tcstyle)

parser = HandleXliffParsing()
xliff = file('global.xlf').read()
chandler = parser.parseXLIFFSTring(xliff)
if chandler is None:
    print "Unable to parse XLIFF file"
    sys.exit(0)

header_info = chandler.getFileTag()
body_info = chandler.getBody() #return a dictionary

uf = UserFieldDecls()
textdoc.text.addElement(uf)

# Add user fields
for id,transunit in body_info.items():
    uf.addElement(UserFieldDecl(name=id,valuetype="string", stringvalue=transunit['target']))