summaryrefslogtreecommitdiffstats
path: root/tools/linguist/shared/qph.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/linguist/shared/qph.cpp')
-rw-r--r--tools/linguist/shared/qph.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/tools/linguist/shared/qph.cpp b/tools/linguist/shared/qph.cpp
index 788245c..32bdabb 100644
--- a/tools/linguist/shared/qph.cpp
+++ b/tools/linguist/shared/qph.cpp
@@ -81,14 +81,20 @@ bool QPHReader::read(Translator &translator)
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 @@ bool QPHReader::read(Translator &translator)
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 @@ static bool saveQPH(const Translator &translator, QIODevice &dev, ConversionData
{
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 @@ static bool saveQPH(const Translator &translator, QIODevice &dev, ConversionData
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";