Logo Search packages:      
Sourcecode: kaider-kde4 version File versions  Download package

void GettextExportPlugin::writeKeyword ( QTextStream &  stream,
const QString &  keyword,
const QString &  text 
) const [private]

Write a PO keyword (msgctxt, msgid, msgstr, msgstr_plural, msgstr[0]) and the corresponding text. This includes wrapping the text.

Definition at line 271 of file gettextexport.cpp.

References m_wrapWidth.

{
    if ( text.isEmpty() )
    {
        // Whatever the wrapping mode, an empty line is an empty line
        stream << keyword << " \"\"\n";
        return; 
    }

    if ( m_wrapWidth == -1 )
    {
        // Traditional KBabel wrapping
        QStringList list = text.split( '\n', QString::SkipEmptyParts );

        if ( text.startsWith( '\n' ) )
            list.prepend( QString() );

        if(list.isEmpty())
            list.append( QString() );
    
        if( list.count() > 1 )
            list.prepend( QString() );

        stream << keyword << ' ';
    
        QStringList::const_iterator it;
        for( it = list.constBegin(); it != list.constEnd(); ++it )
        {
            stream << '\"' << (*it) << "\"\n";
        }
        return;
    }

    if ( m_wrapWidth <= 0 ) // Unknown special wrapping, so assume "no wrap" instead
    {
        // No wrapping (like Gettext's --no.wrap or -w0 )
        // we need to remove the \n characters, as they are extra characters
        QString realText( text );
        realText.remove( '\n' );
        stream << keyword << " \"" << realText << "\"\n";
        return;
    }

    // lazy wrapping
    QStringList list = text.split( '\n', QString::SkipEmptyParts );

    if ( text.startsWith( '\n' ) )
        list.prepend( QString() );

    if(list.isEmpty())
        list.append( QString() );

    int max=m_wrapWidth-2;
    bool prependedEmptyLine=false;
    QStringList::iterator itm;
    for( itm = list.begin(); itm != list.end(); ++itm )
    {
        if (list.count()==1 && itm->length()>max-keyword.length()-1)
        {
            prependedEmptyLine=true;
            itm=list.insert(itm,"");
        }

        if (itm->length()>max)
        {
            int pos = itm->lastIndexOf(QRegExp("[ >.]"),max-1);
            if (pos>0)
            {
                int pos2 = itm->indexOf('<',pos);
                if (pos2>0&&pos2<max-1)
                    pos=itm->indexOf('<',pos);
                ++pos;
            }
            else
                pos=max;
            //itm=list.insert(itm,itm->left(pos));
            QString t=*itm;
            itm=list.insert(itm,t);
            itm++;
            (*itm)=itm->remove(0,pos);
            itm--;
            itm->truncate(pos);
        }
    }

    if( !prependedEmptyLine && list.count() > 1 )
        list.prepend( QString() );

    stream << keyword << " ";

    QStringList::const_iterator it;
    for( it = list.constBegin(); it != list.constEnd(); ++it )
    {
        stream << "\"" << (*it) << "\"\n";
    }
}


Generated by  Doxygen 1.6.0   Back to index