diff options
author | Lucie Gérard <lucie.gerard@qt.io> | 2019-05-24 10:27:03 +0200 |
---|---|---|
committer | Lucie Gérard <lucie.gerard@qt.io> | 2019-05-24 10:27:03 +0200 |
commit | 945d7c1f00f08fb1cb29bd548e8c4d0a42857f67 (patch) | |
tree | 275ec32792545bf09443e554563a6995f0ef9197 | |
parent | 2c1c1f74ea69d2bdd984b5d5764db08ee77f1e6f (diff) | |
download | qttools-945d7c1f00f08fb1cb29bd548e8c4d0a42857f67.tar.gz |
Remove extra \n when reading translator comment from .po file
Extra \n was added at the end of the translator message (cf slurpComment).
This was visible from the ts file in case of convertion.
But the round trip .po to .ts to .po was correct
because of the way messages are read from the .ts file (cf poEscapedLines)
Both functions are modified, no extra \n is added, the roundtrip works,
autoTest are all passed.
Fixes: QTBUG-67908
Change-Id: Ie55572f9609c71c164b2ab939bf0c0d0ca1afc20
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
-rw-r--r-- | src/linguist/shared/po.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/linguist/shared/po.cpp b/src/linguist/shared/po.cpp index a998aa0f6..4e623e6a3 100644 --- a/src/linguist/shared/po.cpp +++ b/src/linguist/shared/po.cpp @@ -151,7 +151,7 @@ static QString poEscapedLines(const QString &prefix, bool addSpace, const QStrin static QString poEscapedLines(const QString &prefix, bool addSpace, const QString &in0) { QString in = in0; - if (in.endsWith(QLatin1Char('\n'))) + if (in == QString::fromLatin1("\n")) in.chop(1); return poEscapedLines(prefix, addSpace, in.split(QLatin1Char('\n'))); } @@ -321,6 +321,7 @@ premature_eol: static void slurpComment(QByteArray &msg, const QList<QByteArray> &lines, int & l) { + int firstLine = l; QByteArray prefix = lines.at(l); for (int i = 1; ; i++) { if (prefix.at(i) != ' ') { @@ -330,11 +331,15 @@ static void slurpComment(QByteArray &msg, const QList<QByteArray> &lines, int & } for (; l < lines.size(); ++l) { const QByteArray &line = lines.at(l); - if (line.startsWith(prefix)) + if (line.startsWith(prefix)) { + if (l > firstLine) + msg += '\n'; msg += line.mid(prefix.size()); - else if (line != "#") + } else if (line == "#") { + msg += '\n'; + } else { break; - msg += '\n'; + } } --l; } @@ -525,9 +530,10 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) } } doneho: - if (lastCmtLine != -1) + if (lastCmtLine != -1) { extras[QLatin1String("po-header_comment")] = QByteArrayList_join(lines.mid(0, lastCmtLine + 1), '\n'); + } for (QHash<QString, QByteArray>::ConstIterator it = extras.constBegin(), end = extras.constEnd(); it != end; ++it) @@ -626,7 +632,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd) item.id = line.mid(9); } else { item.automaticComments += line.mid(3); - item.automaticComments += '\n'; + } break; case '|': |