summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Hanselmann <public@hansmi.ch>2016-01-14 13:59:28 +0100
committerMichael Hanselmann <public@hansmi.ch>2016-01-15 13:42:47 +0000
commit69984af8d5465feb9532823f112f322d5404cc15 (patch)
treea73c931cf40fb1c8c1c4f30d58bddeceef91167d
parent1c4ee969c20e4285754f81de13f54f1d0cc2b82c (diff)
lupdate: Handle translation comments in ternary expressions
When the condition in a ternary operator expression was anything more than a single identifier translation comments were not recognized for translations within the values. Re-enabling translator comment detection after the question mark fixes that. Task-number: QTBUG-48776 Change-Id: I83bb9efaab42c52fc05a39094060eb0a1fb76d94 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
-rw-r--r--src/linguist/lupdate/cpp.cpp6
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp41
-rw-r--r--tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result49
3 files changed, 95 insertions, 1 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp
index 963e5c53f..0d5a7a8d9 100644
--- a/src/linguist/lupdate/cpp.cpp
+++ b/src/linguist/lupdate/cpp.cpp
@@ -233,7 +233,7 @@ private:
Tok_Eof, Tok_class, Tok_friend, Tok_namespace, Tok_using, Tok_return,
Tok_Q_OBJECT, Tok_Access, Tok_Cancel,
Tok_Ident, Tok_String, Tok_Arrow, Tok_Colon, Tok_ColonColon,
- Tok_Equals, Tok_LeftBracket, Tok_RightBracket,
+ Tok_Equals, Tok_LeftBracket, Tok_RightBracket, Tok_QuestionMark,
Tok_LeftBrace, Tok_RightBrace, Tok_LeftParen, Tok_RightParen, Tok_Comma, Tok_Semicolon,
Tok_Null, Tok_Integer,
Tok_QuotedInclude, Tok_AngledInclude,
@@ -904,6 +904,9 @@ CppParser::TokenType CppParser::getToken()
case ';':
yyCh = getChar();
return Tok_Semicolon;
+ case '?':
+ yyCh = getChar();
+ return Tok_QuestionMark;
case '0':
yyCh = getChar();
if (yyCh == 'x') {
@@ -2089,6 +2092,7 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac
// fallthrough
case Tok_Comma:
case Tok_LeftParen:
+ case Tok_QuestionMark:
metaExpected = true;
yyTok = getToken();
break;
diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
index 6be775994..f4ac1e214 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
@@ -447,3 +447,44 @@ class Abc::NamespacedFinalClass final : public QObject
tr("namespaced class with final");
}
};
+
+
+
+// QTBUG-48776: lupdate fails to recognize translator comment in ternary
+// operator construct
+void ternary()
+{
+ const auto aaa =
+ obj.condition ?
+ //: comment, aaa, true
+ QObject::tr("ternary, true, aaa") :
+ QObject::tr("ternary, failure, aaa");
+
+ const auto bbb =
+ obj.condition ?
+ //: comment, bbb, true
+ QObject::tr("ternary, bbb, true") :
+ //: comment, bbb, false
+ QObject::tr("ternary, bbb, false");
+}
+
+class TernaryClass : public QObject
+{
+ Q_OBJECT
+
+ void f()
+ {
+ const auto ccc =
+ obj.condition ?
+ //: comment, ccc, true
+ tr("ternary, ccc, true") :
+ tr("ternary, ccc, false");
+
+ const auto ddd =
+ obj.condition ?
+ //: comment, ddd, true
+ tr("ternary, ddd, true") :
+ //: comment, ddd, false
+ tr("ternary, ddd, false");
+ }
+};
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 be393f9d7..b847f8f89 100644
--- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
+++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result
@@ -280,6 +280,29 @@ backslashed \ stuff.</source>
<translation type="unfinished"></translation>
</message>
<message>
+ <location filename="main.cpp" line="460"/>
+ <source>ternary, true, aaa</source>
+ <extracomment>comment, aaa, true</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="461"/>
+ <source>ternary, failure, aaa</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="466"/>
+ <source>ternary, bbb, true</source>
+ <extracomment>comment, bbb, true</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="468"/>
+ <source>ternary, bbb, false</source>
+ <extracomment>comment, bbb, false</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
<location filename="included.cpp" line="34"/>
<source>message from #included .cpp file</source>
<translation type="unfinished"></translation>
@@ -332,6 +355,32 @@ backslashed \ stuff.</source>
</message>
</context>
<context>
+ <name>TernaryClass</name>
+ <message>
+ <location filename="main.cpp" line="480"/>
+ <source>ternary, ccc, true</source>
+ <extracomment>comment, ccc, true</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="481"/>
+ <source>ternary, ccc, false</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="486"/>
+ <source>ternary, ddd, true</source>
+ <extracomment>comment, ddd, true</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="main.cpp" line="488"/>
+ <source>ternary, ddd, false</source>
+ <extracomment>comment, ddd, false</extracomment>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+<context>
<name>TestClass</name>
<message>
<location filename="main.cpp" line="149"/>