예제 #1
0
bool MetaTranslator::release( const QString& filename, bool verbose,
                              bool ignoreUnfinished,
                              Translator::SaveMode mode ) const
{
    Translator tor( 0 );
    int finished = 0;
    int unfinished = 0;
    int untranslated = 0;
    TMM::ConstIterator m;

    for ( m = mm.begin(); m != mm.end(); ++m ) {
        if ( m.key().type() != MetaTranslatorMessage::Obsolete ) {
            if ( m.key().translation().isEmpty() ) {
                untranslated++;
            } else {
                if ( m.key().type() == MetaTranslatorMessage::Unfinished )
                    unfinished++;
                else
                    finished++;

                QByteArray context = m.key().context();
                QByteArray sourceText = m.key().sourceText();
                QByteArray comment = m.key().comment();
                QByteArray translatorComment = m.key().translatorComment();
                QStringList translations = m.key().translations();

                if ( !ignoreUnfinished
                     || m.key().type() != MetaTranslatorMessage::Unfinished ) {
                    /*
                      Drop the comment in (context, sourceText, comment),
                      unless the context is empty,
                      unless (context, sourceText, "") already exists or
                      unless we already dropped the comment of (context,
                      sourceText, comment0).
                    */
                    if ( comment.isEmpty()
                         || context.isEmpty()
                         || contains(context, sourceText, "")
                         || !tor.findMessage(context, sourceText, "").translation()
                                .isNull() ) {
                        tor.insert( m.key() );
                    } else {
                        tor.insert( TranslatorMessage(context, sourceText, "", "",
                                                      QString(), -1, translations) );
                        //filename and lineNumbers will be ignored from now.
                    }
                }
            }
        }
    }

    bool saved = tor.save( filename, mode );
    if ( saved && verbose )
        fprintf( stderr,
                 " %d finished, %d unfinished and %d untranslated messages\n",
                 finished, unfinished, untranslated );

    return saved;
}
예제 #2
0
bool XLIFFHandler::endElement(const QString& namespaceURI,
                              const QString& localName, const QString& /*qName*/ )
{
    if (namespaceURI == m_URI || namespaceURI == m_URI12) {
        if (localName == QLatin1String("xliff")) {
            popContext(XC_xliff);
        } else if (localName == QLatin1String("source")) {
            m_source = accum;
        } else if (localName == QLatin1String("target")) {
            translations.append(accum);
        } else if (localName == QLatin1String("context-group")) {
            popContext(XC_context_group);
        } else if (currentContext() == XC_context_linenumber && localName == QLatin1String("context")) {
            bool ok;
            m_lineNumber = accum.trimmed().toInt(&ok);
            if (!ok)
                m_lineNumber = -1;
            popContext(XC_context_linenumber);
        } else if (localName == QLatin1String("note")) {
            m_comment = accum;
        } else if (localName == QLatin1String("ph")) {
            m_ctype.clear();
            popContext(XC_ph);
        } else if (localName == QLatin1String("trans-unit")) {
            if (!hasContext(XC_restype_plurals)) {
                tor->insert( TranslatorMessage(m_context.toUtf8(), m_source.toUtf8(),
                                                m_comment.toUtf8(), "", m_fileName, m_lineNumber,
                                                translations, true, m_type, false) );
                translations.clear();
                m_lineNumber = -1;
            }
        } else if (localName == QLatin1String("group")) {
            if (hasContext(XC_restype_plurals)) {
                tor->insert( TranslatorMessage(m_context.toUtf8(), m_source.toUtf8(),
                                                m_comment.toUtf8(), "", m_fileName, m_lineNumber,
                                                translations, true, m_type, true) );
                popContext(XC_restype_plurals);
                translations.clear();
                m_lineNumber = -1;
            }
            popContext(XC_group);
        }
        return true;
    }
    return false;
}