tools/linguist/shared/qph.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/tools/linguist/shared/qph.cpp	Tue Jan 26 12:42:25 2010 +0200
+++ b/tools/linguist/shared/qph.cpp	Tue Feb 02 00:43:10 2010 +0200
@@ -81,14 +81,20 @@
     while (!atEnd()) {
         readNext();
         if (isStartElement()) {
-            if (name() == QLatin1String("source"))
+            if (name() == QLatin1String("source")) {
                 m_currentField = SourceField;
-            else if (name() == QLatin1String("target"))
+            } else if (name() == QLatin1String("target")) {
                 m_currentField = TargetField;
-            else if (name() == QLatin1String("definition"))
+            } else if (name() == QLatin1String("definition")) {
                 m_currentField = DefinitionField;
-            else
+            } else {
                 m_currentField = NoField;
+                if (name() == QLatin1String("QPH")) {
+                    QXmlStreamAttributes atts = attributes();
+                    translator.setLanguageCode(atts.value(QLatin1String("language")).toString());
+                    translator.setSourceLanguageCode(atts.value(QLatin1String("sourcelanguage")).toString());
+                }
+            }
         } else if (isWhiteSpace()) {
             // ignore these
         } else if (isCharacters()) {
@@ -104,7 +110,7 @@
             TranslatorMessage msg;
             msg.setSourceText(m_currentSource);
             msg.setTranslation(m_currentTarget);
-            msg.setTranslatorComment(m_currentDefinition);
+            msg.setComment(m_currentDefinition);
             translator.append(msg);
             m_currentSource.clear();
             m_currentTarget.clear();
@@ -157,7 +163,14 @@
 {
     QTextStream t(&dev);
     t.setCodec(QTextCodec::codecForName("UTF-8"));
-    t << "<!DOCTYPE QPH>\n<QPH>\n";
+    t << "<!DOCTYPE QPH>\n<QPH";
+    QString languageCode = translator.languageCode();
+    if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
+        t << " language=\"" << languageCode << "\"";
+    languageCode = translator.sourceLanguageCode();
+    if (!languageCode.isEmpty() && languageCode != QLatin1String("C"))
+        t << " sourcelanguage=\"" << languageCode << "\"";
+    t << ">\n";
     foreach (const TranslatorMessage &msg, translator.messages()) {
         t << "<phrase>\n";
         t << "    <source>" << protect(msg.sourceText()) << "</source>\n";
@@ -166,9 +179,8 @@
                     QChar(Translator::TextVariantSeparator));
         t << "    <target>" << protect(str)
             << "</target>\n";
-        if (!msg.context().isEmpty() || !msg.comment().isEmpty())
-            t << "    <definition>" << msg.context() << msg.comment()
-                << "</definition>\n";
+        if (!msg.comment().isEmpty())
+            t << "    <definition>" << protect(msg.comment()) << "</definition>\n";
         t << "</phrase>\n";
     }
     t << "</QPH>\n";