From e2ac68f3437ab6e9e865c7c9ad1c52b293f61910 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 23 Mar 2011 20:05:49 +0100 Subject: fix detection of relative location information an empty line number does not indicate relative loc info - it may be the result of -no-ui-lines. instead, an empty file name does indicate it - no file name at all makes no sense, so this means a previous messages has set it already. and we need this additional detection, as the entire ts file may have no line number info to base the decision on at all. --- tools/linguist/shared/ts.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/linguist/shared/ts.cpp b/tools/linguist/shared/ts.cpp index 85be5c6..4523bc5 100644 --- a/tools/linguist/shared/ts.cpp +++ b/tools/linguist/shared/ts.cpp @@ -264,6 +264,7 @@ bool TSReader::read(Translator &translator) //qDebug() << "TS " << attributes(); QHash currentLine; QString currentFile; + bool maybeRelative = false, maybeAbsolute = false; QXmlStreamAttributes atts = attributes(); //QString version = atts.value(strversion).toString(); @@ -342,10 +343,12 @@ bool TSReader::read(Translator &translator) msg.setTranslatorComment(readContents()); } else if (elementStarts(strlocation)) { // + maybeAbsolute = true; QXmlStreamAttributes atts = attributes(); QString fileName = atts.value(strfilename).toString(); if (fileName.isEmpty()) { fileName = currentMsgFile; + maybeRelative = true; } else { if (refs.isEmpty()) currentFile = fileName; @@ -353,7 +356,6 @@ bool TSReader::read(Translator &translator) } const QString lin = atts.value(strline).toString(); if (lin.isEmpty()) { - translator.setLocationsType(Translator::RelativeLocations); refs.append(TranslatorMessage::Reference(fileName, -1)); } else { bool bOK; @@ -361,9 +363,7 @@ bool TSReader::read(Translator &translator) if (bOK) { if (lin.startsWith(QLatin1Char('+')) || lin.startsWith(QLatin1Char('-'))) { lineNo = (currentLine[fileName] += lineNo); - translator.setLocationsType(Translator::RelativeLocations); - } else { - translator.setLocationsType(Translator::AbsoluteLocations); + maybeRelative = true; } refs.append(TranslatorMessage::Reference(fileName, lineNo)); } @@ -422,6 +422,9 @@ bool TSReader::read(Translator &translator) } else { handleError(); } + translator.setLocationsType(maybeRelative ? Translator::RelativeLocations : + maybeAbsolute ? Translator::AbsoluteLocations : + Translator::NoLocations); } // } else { handleError(); @@ -727,7 +730,6 @@ bool saveTS(const Translator &translator, QIODevice &dev, ConversionData &cd, in bool loadTS(Translator &translator, QIODevice &dev, ConversionData &cd) { - translator.setLocationsType(Translator::NoLocations); TSReader reader(dev, cd); return reader.read(translator); } -- cgit v0.12