diff options
author | Johnny Jazeix <jazeix@gmail.com> | 2023-02-04 22:15:06 +0100 |
---|---|---|
committer | Johnny Jazeix <jazeix@gmail.com> | 2023-02-17 19:13:44 +0100 |
commit | d8dad5d13cd35a298b0fb7f489f552de2c5f175d (patch) | |
tree | ad8afd7bbb4aebb33742988a16069c3120cb6ffd | |
parent | da526cfbfd97e662301965484241a6e9311d7fd9 (diff) | |
download | qttools-d8dad5d13cd35a298b0fb7f489f552de2c5f175d.tar.gz |
Handle text in quotes in extra comments in lupdate
Allows to have text in extra comment within quotes that will be kept
intact when running lupdate.
Fixes: QTBUG-110630
Co-authored-by: Kai Köhne <kai.koehne@qt.io>
Change-Id: I267e779193f168a8af067b927735991f2c512145
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
8 files changed, 52 insertions, 4 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index d86481fdc..cc56f2d5d 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -2107,8 +2107,14 @@ void CppParser::processComment() yyWord.remove(0, 2); text = yyWord.trimmed(); int k = text.indexOf(QLatin1Char(' ')); - if (k > -1) - extra.insert(text.left(k), text.mid(k + 1).trimmed()); + if (k > -1) { + QString commentvalue = text.mid(k + 1).trimmed(); + if (commentvalue.startsWith(QLatin1Char('"')) && commentvalue.endsWith(QLatin1Char('"')) + && commentvalue.size() != 1) { + commentvalue = commentvalue.sliced(1, commentvalue.size() - 2); + } + extra.insert(text.left(k), commentvalue); + } text.clear(); } else if (*ptr == QLatin1Char('%') && ptr[1].isSpace()) { sourcetext.reserve(sourcetext.size() + yyWord.size() - 2); diff --git a/src/linguist/lupdate/qdeclarative.cpp b/src/linguist/lupdate/qdeclarative.cpp index 1aabc6eca..4cc9b8b94 100644 --- a/src/linguist/lupdate/qdeclarative.cpp +++ b/src/linguist/lupdate/qdeclarative.cpp @@ -329,8 +329,14 @@ void FindTrCalls::processComment(const SourceLocation &loc) } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) { QString text = QString(chars+2, length-2).trimmed(); int k = text.indexOf(QLatin1Char(' ')); - if (k > -1) - extra.insert(text.left(k), text.mid(k + 1).trimmed()); + if (k > -1) { + QString commentvalue = text.mid(k + 1).trimmed(); + if (commentvalue.startsWith(QLatin1Char('"')) && commentvalue.endsWith(QLatin1Char('"')) + && commentvalue.size() != 1) { + commentvalue = commentvalue.sliced(1, commentvalue.size() - 2); + } + extra.insert(text.left(k), commentvalue); + } } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) { sourcetext.reserve(sourcetext.size() + length-2); ushort *ptr = (ushort *)sourcetext.data() + sourcetext.size(); diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp index a1d4ed4fe..43b493203 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp @@ -709,3 +709,12 @@ class QTBUG99415 : QObject { }; const QString QTBUG99415::text2() const noexcept { return tr("text2"); } + +// QTBUG-110630: Support quoting in extras field to allow whitespace preservation +class QTBUG110630 : QObject { + Q_OBJECT + const QString txt() { + //~ quoted " string with spaces " + tr("translation with extras-quoted field"); + } +}; diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result index f21258d87..bf3c20877 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -422,6 +422,15 @@ backslashed \ stuff.</source> </message> </context> <context> + <name>QTBUG110630</name> + <message> + <location filename="main.cpp" line="718"/> + <source>translation with extras-quoted field</source> + <translation type="unfinished"></translation> + <extra-quoted> string with spaces </extra-quoted> + </message> +</context> +<context> <name>QTBUG99415</name> <message> <location filename="main.cpp" line="707"/> diff --git a/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js b/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js index 9f61cea8f..964ec72a1 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js +++ b/tests/auto/linguist/lupdate/testdata/good/parsejs/main.js @@ -89,3 +89,6 @@ var more_greeting_strings = [ QT_TRID_NOOP("qtn_needle"), QT_TRID_NOOP("qtn_hays //: qsTrId() with comment, meta-data and plurals. //~ well-tested True qsTrId("qtn_bar_baz", 10); + +//~ quoted " string with spaces " +qsTr("translation with extras-quoted field"); diff --git a/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result index 8df655fec..b505d3608 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsejs/project.ts.result @@ -191,5 +191,11 @@ <numerusform></numerusform> </translation> </message> + <message> + <location filename="main.js" line="94"/> + <source>translation with extras-quoted field</source> + <translation type="unfinished"></translation> + <extra-quoted> string with spaces </extra-quoted> + </message> </context> </TS> diff --git a/tests/auto/linguist/lupdate/testdata/good/parseqml/main.qml b/tests/auto/linguist/lupdate/testdata/good/parseqml/main.qml index c966fa112..e25750193 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parseqml/main.qml +++ b/tests/auto/linguist/lupdate/testdata/good/parseqml/main.qml @@ -96,5 +96,8 @@ QtObject { //% "Source text" qsTrId("qtn_baz_biz"); + + //~ quoted " string with spaces " + qsTr("translation with extras-quoted field"); } } diff --git a/tests/auto/linguist/lupdate/testdata/good/parseqml/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parseqml/project.ts.result index ce57bd44d..ecdfc8b34 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parseqml/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parseqml/project.ts.result @@ -196,5 +196,11 @@ <numerusform></numerusform> </translation> </message> + <message> + <location filename="main.qml" line="101"/> + <source>translation with extras-quoted field</source> + <translation type="unfinished"></translation> + <extra-quoted> string with spaces </extra-quoted> + </message> </context> </TS> |