예제 #1
0
bool TsHandler::startElement( const QString& /* namespaceURI */,
                              const QString& /* localName */,
                              const QString& qName,
                              const QXmlAttributes& atts )
{
    if ( qName == QString("byte") ) {
        for ( int i = 0; i < atts.length(); i++ ) {
            if ( atts.qName(i) == QString("value") ) {
                QString value = atts.value( i );
                int base = 10;
                if ( value.startsWith("x") ) {
                    base = 16;
                    value = value.mid( 1 );
                }
                int n = value.toUInt( 0, base );
                if ( n != 0 )
                    accum += QChar( n );
            }
        }
    } else {
        if ( qName == QString("TS") ) {
            m_language = atts.value(QLatin1String("language"));
        } else if ( qName == QString("context") ) {
            context.truncate( 0 );
            source.truncate( 0 );
            comment.truncate( 0 );
            m_translatorComment.truncate( 0 );
            translations.clear();
            contextIsUtf8 = encodingIsUtf8( atts );
        } else if ( qName == QString("message") ) {
            inMessage = true;
            type = MetaTranslatorMessage::Finished;
            source.truncate( 0 );
            comment.truncate( 0 );
            m_translatorComment.truncate( 0 );
            translations.clear();
            messageIsUtf8 = encodingIsUtf8( atts );
            m_isPlural = atts.value(QLatin1String("numerus")).compare(QLatin1String("yes")) == 0;
        } else if (qName == QString("location") && inMessage) {
            bool bOK;
            int lineNo = atts.value(QString("line")).toInt(&bOK);
            if (!bOK) lineNo = -1;
            m_fileName = atts.value(QString("filename"));
            m_lineNumber = lineNo;
        } else if ( qName == QString("translation") ) {
            for ( int i = 0; i < atts.length(); i++ ) {
                if ( atts.qName(i) == QString("type") ) {
                    if ( atts.value(i) == QString("unfinished") )
                        type = MetaTranslatorMessage::Unfinished;
                    else if ( atts.value(i) == QString("obsolete") )
                        type = MetaTranslatorMessage::Obsolete;
                    else
                        type = MetaTranslatorMessage::Finished;
                }
            }
        }
        accum.truncate( 0 );
    }
    return true;
}
bool TsHandler::startElement( const QString& /* namespaceURI */, const QString& /* localName */, const QString& qName, const QXmlAttributes& atts )
{
	if ( qName == QString( "byte" ) )
	{
		for ( int i = 0; i < atts.length(); i++ )
		{
			if ( atts.qName( i ) == QString( "value" ) )
			{
				QString value = atts.value( i );
				int base = 10;
				if ( value.startsWith( "x" ) )
				{
					base = 16;
					value = value.mid( 1 );
				}
				int n = value.toUInt( 0, base );
				if ( n != 0 )
					accum += QChar( n );
			}
		}
	}
	else
	{
		if ( qName == QString( "context" ) )
		{
			context.truncate( 0 );
			source.truncate( 0 );
			comment.truncate( 0 );
			translation.truncate( 0 );
			contextIsUtf8 = encodingIsUtf8( atts );
		}
		else if ( qName == QString( "message" ) )
		{
			inMessage = TRUE;
			type = MetaTranslatorMessage::Finished;
			source.truncate( 0 );
			comment.truncate( 0 );
			translation.truncate( 0 );
			messageIsUtf8 = encodingIsUtf8( atts );
		}
		else if ( qName == QString( "translation" ) )
		{
			for ( int i = 0; i < atts.length(); i++ )
			{
				if ( atts.qName( i ) == QString( "type" ) )
				{
					if ( atts.value( i ) == QString( "unfinished" ) )
						type = MetaTranslatorMessage::Unfinished;
					else if ( atts.value( i ) == QString( "obsolete" ) )
						type = MetaTranslatorMessage::Obsolete;
					else
						type = MetaTranslatorMessage::Finished;
				}
			}
		}
		accum.truncate( 0 );
	}
	return TRUE;
}