Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/tools/linguist/shared/qph.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the Qt Linguist of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5555{
    5656public:
    57     QPHReader(QIODevice &dev, ConversionData &cd)
    58       : QXmlStreamReader(&dev), m_cd(cd)
     57    QPHReader(QIODevice &dev)
     58      : QXmlStreamReader(&dev)
    5959    {}
    6060
     
    6363
    6464private:
    65     bool elementStarts(const QString &str) const
    66     {
    67         return isStartElement() && name() == str;
    68     }
    69 
    7065    bool isWhiteSpace() const
    7166    {
    7267        return isCharacters() && text().toString().trimmed().isEmpty();
    7368    }
    74 
    75     // needed to expand <byte ... />
    76     QString readContents();
    77     // needed to join <lengthvariant>s
    78     QString readTransContents();
    79 
    80     void handleError();
    81 
    82     ConversionData &m_cd;
    8369
    8470    enum DataField { NoField, SourceField, TargetField, DefinitionField };
     
    9682        readNext();
    9783        if (isStartElement()) {
    98             if (name() == QLatin1String("source"))
     84            if (name() == QLatin1String("source")) {
    9985                m_currentField = SourceField;
    100             else if (name() == QLatin1String("target"))
     86            } else if (name() == QLatin1String("target")) {
    10187                m_currentField = TargetField;
    102             else if (name() == QLatin1String("definition"))
     88            } else if (name() == QLatin1String("definition")) {
    10389                m_currentField = DefinitionField;
    104             else
     90            } else {
    10591                m_currentField = NoField;
     92                if (name() == QLatin1String("QPH")) {
     93                    QXmlStreamAttributes atts = attributes();
     94                    translator.setLanguageCode(atts.value(QLatin1String("language")).toString());
     95                    translator.setSourceLanguageCode(atts.value(QLatin1String("sourcelanguage")).toString());
     96                }
     97            }
    10698        } else if (isWhiteSpace()) {
    10799            // ignore these
     
    114106                m_currentDefinition += text();
    115107        } else if (isEndElement() && name() == QLatin1String("phrase")) {
     108            m_currentTarget.replace(QChar(Translator::TextVariantSeparator),
     109                                    QChar(Translator::BinaryVariantSeparator));
    116110            TranslatorMessage msg;
    117111            msg.setSourceText(m_currentSource);
    118112            msg.setTranslation(m_currentTarget);
    119             msg.setTranslatorComment(m_currentDefinition);
     113            msg.setComment(m_currentDefinition);
    120114            translator.append(msg);
    121115            m_currentSource.clear();
     
    127121}
    128122
    129 static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData &cd)
     123static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData &)
    130124{
    131125    translator.setLocationsType(Translator::NoLocations);
    132     QPHReader reader(dev, cd);
     126    QPHReader reader(dev);
    133127    return reader.read(translator);
    134128}
     
    170164    QTextStream t(&dev);
    171165    t.setCodec(QTextCodec::codecForName("UTF-8"));
    172     t << "<!DOCTYPE QPH>\n<QPH>\n";
     166    t << "<!DOCTYPE QPH>\n<QPH";
     167    QString languageCode = translator.languageCode();
     168    if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
     169        t << " language=\"" << languageCode << "\"";
     170    languageCode = translator.sourceLanguageCode();
     171    if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
     172        t << " sourcelanguage=\"" << languageCode << "\"";
     173    t << ">\n";
    173174    foreach (const TranslatorMessage &msg, translator.messages()) {
    174175        t << "<phrase>\n";
    175176        t << "    <source>" << protect(msg.sourceText()) << "</source>\n";
    176         t << "    <target>" << protect(msg.translations().join(QLatin1String("@")))
     177        QString str = msg.translations().join(QLatin1String("@"));
     178        str.replace(QChar(Translator::BinaryVariantSeparator),
     179                    QChar(Translator::TextVariantSeparator));
     180        t << "    <target>" << protect(str)
    177181            << "</target>\n";
    178         if (!msg.context().isEmpty() || !msg.comment().isEmpty())
    179             t << "    <definition>" << msg.context() << msg.comment()
    180                 << "</definition>\n";
     182        if (!msg.comment().isEmpty())
     183            t << "    <definition>" << protect(msg.comment()) << "</definition>\n";
    181184        t << "</phrase>\n";
    182185    }
Note: See TracChangeset for help on using the changeset viewer.