Changeset 561 for trunk/tools/linguist/shared/qph.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/tools/linguist/shared/qph.cpp
r2 r561 2 2 ** 3 3 ** 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) 5 6 ** 6 7 ** This file is part of the Qt Linguist of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 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. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** 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. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 55 55 { 56 56 public: 57 QPHReader(QIODevice &dev , ConversionData &cd)58 : QXmlStreamReader(&dev) , m_cd(cd)57 QPHReader(QIODevice &dev) 58 : QXmlStreamReader(&dev) 59 59 {} 60 60 … … 63 63 64 64 private: 65 bool elementStarts(const QString &str) const66 {67 return isStartElement() && name() == str;68 }69 70 65 bool isWhiteSpace() const 71 66 { 72 67 return isCharacters() && text().toString().trimmed().isEmpty(); 73 68 } 74 75 // needed to expand <byte ... />76 QString readContents();77 // needed to join <lengthvariant>s78 QString readTransContents();79 80 void handleError();81 82 ConversionData &m_cd;83 69 84 70 enum DataField { NoField, SourceField, TargetField, DefinitionField }; … … 96 82 readNext(); 97 83 if (isStartElement()) { 98 if (name() == QLatin1String("source")) 84 if (name() == QLatin1String("source")) { 99 85 m_currentField = SourceField; 100 else if (name() == QLatin1String("target"))86 } else if (name() == QLatin1String("target")) { 101 87 m_currentField = TargetField; 102 else if (name() == QLatin1String("definition"))88 } else if (name() == QLatin1String("definition")) { 103 89 m_currentField = DefinitionField; 104 else90 } else { 105 91 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 } 106 98 } else if (isWhiteSpace()) { 107 99 // ignore these … … 114 106 m_currentDefinition += text(); 115 107 } else if (isEndElement() && name() == QLatin1String("phrase")) { 108 m_currentTarget.replace(QChar(Translator::TextVariantSeparator), 109 QChar(Translator::BinaryVariantSeparator)); 116 110 TranslatorMessage msg; 117 111 msg.setSourceText(m_currentSource); 118 112 msg.setTranslation(m_currentTarget); 119 msg.set TranslatorComment(m_currentDefinition);113 msg.setComment(m_currentDefinition); 120 114 translator.append(msg); 121 115 m_currentSource.clear(); … … 127 121 } 128 122 129 static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData & cd)123 static bool loadQPH(Translator &translator, QIODevice &dev, ConversionData &) 130 124 { 131 125 translator.setLocationsType(Translator::NoLocations); 132 QPHReader reader(dev , cd);126 QPHReader reader(dev); 133 127 return reader.read(translator); 134 128 } … … 170 164 QTextStream t(&dev); 171 165 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"; 173 174 foreach (const TranslatorMessage &msg, translator.messages()) { 174 175 t << "<phrase>\n"; 175 176 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) 177 181 << "</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"; 181 184 t << "</phrase>\n"; 182 185 }
Note:
See TracChangeset
for help on using the changeset viewer.