1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 // IMPORTANT!!!! If you want to add testdata to this file,
43 // always add it to the end in order to not change the linenumbers of translations!!!
main(char ** argv,int argc)44 int main(char **argv, int argc)
45 {
46 Size size = QSize(1,1);
47 }
48
qt_detectRTLLanguage()49 QString qt_detectRTLLanguage()
50 {
51 return QApplication::tr("QT_LAYOUT_DIRECTION",
52 "Translate this string to the string 'LTR' in left-to-right"
53 " languages or to 'RTL' in right-to-left languages (such as Hebrew"
54 " and Arabic) to get proper widget layout.") == QLatin1String("RTL");
55 }
56
57
58 class Dialog2 : public QDialog
59 {
60 Q_OBJECT
61 void func();
62 void func3();
getCount() const63 int getCount() const { return 2; }
64
65 };
66
func()67 void Dialog2::func()
68 {
69 int n = getCount();
70 tr("%n files", "plural form", n);
71 tr("%n cars", 0, n);
72 tr("&Find %n cars", 0, n);
73 tr("Search in %n items?", 0, n);
74 tr("%1. Search in %n items?", 0, n);
75 tr("Age: %1");
76 tr("There are %n house(s)", "Plurals and function call", getCount());
77
78
79
80
81 QCoreApplication::translate("Plurals, QCoreApplication", "%n house(s)", "Plurals and identifier", QCoreApplication::UnicodeUTF8, n);
82 QCoreApplication::translate("Plurals, QCoreApplication", "%n car(s)", "Plurals and literal number", QCoreApplication::UnicodeUTF8, 1);
83 QCoreApplication::translate("Plurals, QCoreApplication", "%n horse(s)", "Plurals and function call", QCoreApplication::UnicodeUTF8, getCount());
84
85
86
87
88
89
90
91
92 QTranslator trans;
93 trans.translate("QTranslator", "Simple");
94 trans.translate("QTranslator", "Simple", 0);
95 trans.translate("QTranslator", "Simple with comment", "with comment");
96 trans.translate("QTranslator", "Plural without comment", 0, 1);
97 trans.translate("QTranslator", "Plural with comment", "comment 1", n);
98 trans.translate("QTranslator", "Plural with comment", "comment 2", getCount());
99
100
101
102
103
104
105
106
107
108
109
110
111 }
112
113
114
115
116 /* This is actually a test of how many alternative ways a struct/class can be found in a source file.
117 * Due to the simple parser in lupdate, it will actually not treat the remaining lines in the define
118 * as a macro, which is a case the 'Tok_Class' parser block might not consider, and it might loop infinite
119 * if it just tries to fetch the next token until it gets a '{' or a ';'. Another pitfall is that the
120 * context of tr("func3") might not be parsed, it won't resume normal evaluation until the '{' after the function
121 * signature.
122 *
123 */
124 typedef struct S_
125 {
126 int a;
127 } S, *SPtr;
128 class ForwardDecl;
129
130
131 #define FT_DEFINE_SERVICE( name ) \
132 typedef struct FT_Service_ ## name ## Rec_ \
133 FT_Service_ ## name ## Rec ; \
134 typedef struct FT_Service_ ## name ## Rec_ \
135 const * FT_Service_ ## name ; \
136 struct FT_Service_ ## name ## Rec_
137
138
139 /* removing this comment will break this test */
140
func3()141 void Dialog2::func3()
142 {
143 tr("func3");
144 }
145
146
147
148
149 namespace Gui { class BaseClass {}; }
150
151
152 class TestClass : QObject {
153 Q_OBJECT
154
155
inlineFunc1()156 inline QString inlineFunc1() {
157 return tr("inline function", "TestClass");
158 }
159
inlineFunc2()160 QString inlineFunc2() {
161 return tr("inline function 2", "TestClass");
162 }
163
staticInlineFunc()164 static inline QString staticInlineFunc() {
165 return tr("static inline function", "TestClass");
166 }
167
168 class NoQObject : public Gui::BaseClass {
169 public:
hello()170 inline QString hello() { return QString("hello"); }
171
172 };
173
174 };
175
176
177 class Testing : QObject {
178 Q_OBJECT
179
f1()180 inline QString f1() {
181 //: this is an extra comment for the translator
182 return tr("extra-commented string");
183 return tr("not extra-commented string");
184 /*: another extra-comment */
185 return tr("another extra-commented string");
186 /*: blah! */
187 return QApplication::translate("scope", "works in translate, too", "blabb", 0);
188 }
189
190 };
191
192 //: extra comment for NOOP
193 //: which spans multiple lines
194 QT_TRANSLATE_NOOP("scope", "string") // 4.4 says the line of this is at the next statement
195 //: extra comment for NOOP3
196 QT_TRANSLATE_NOOP3_UTF8("scope", "string", "comment") // 4.4 doesn't see this
197
198 QT_TRANSLATE_NOOP("scope", "string " // this is an interleaved comment
199 "continuation on next line")
200
201
202 class TestingTake17 : QObject {
203 Q_OBJECT
204
function(void)205 int function(void)
206 {
207 //: random comment
208 //= this_is_an_id
209 //~ loc-layout_id fooish_bar
210 //~ po-ignore_me totally foo-barred nonsense
211 tr("something cool");
212
213 tr("less cool");
214
215 //= another_id
216 tr("even more cool");
217 }
218 };
219
220
221
222
223 //: again an extra comment, this time for id-based NOOP
224 //% "This is supposed\tto be quoted \" newline\n"
225 //% "backslashed \\ stuff."
226 QT_TRID_NOOP("this_a_id")
227
228 //~ some thing
229 //% "This needs to be here. Really."
230 QString test = qtTrId("this_another_id", n);
231
232
233
234 class YetAnotherTest : QObject {
235 Q_OBJECT
236
function(void)237 int function(void)
238 {
239 //
240 //:
241 //=
242 //~
243 //#
244 //=============
245 //~~~~~~~~~~~~~
246 //:::::::::::::
247 tr("nothing");
248 }
249 };
250
251
252
253 //: This is a message without a source string
254 QString test = qtTrId("yet_another_id");
255
256
257
258 // QTBUG-9276: context in static initializers
259 class Bogus : QObject {
260 Q_OBJECT
261
262 static const char * const s_strings[];
263 };
264
265 const char * const Bogus::s_strings[] = {
266 QT_TR_NOOP("this should be in Bogus")
267 };
268
269 const char * const Bogus::s_strings[SIZE] = {
270 QT_TR_NOOP("this should be in Bogus")
271 };
272
bogosity()273 void bogosity()
274 {
275 // no spaces here. test collateral damage from ignoring equal sign
276 Class::member=QObject::tr("just QObject");
277 }
278
279
280
281 namespace Internal {
282
283 class Message : public QObject
284 {
285 Q_OBJECT
286 public:
287 Message(QObject *parent = 0);
288 };
289
290 } // The temporary closing of the namespace triggers the problem
291
292 namespace Internal {
293
message1()294 static inline QString message1()
295 {
296 return Message::tr("message1"); // Had no namespace
297 }
298
message2()299 static inline QString message2()
300 {
301 return Message::tr("message2"); // Already had namespace
302 }
303
304 }
305
306
307
308 // QTBUG-11426: operator overloads
309 class LotsaFun : public QObject
310 {
311 Q_OBJECT
312 public:
313 int operator<<(int left, int right);
314 };
315
operator <<(int left,int right)316 int LotsaFun::operator<<(int left, int right)
317 {
318 tr("this is inside operator<<");
319 return left << right;
320 }
321
322
323
324 // QTBUG-12683: define in re-opened namespace
325 namespace NameSchpace {
326
327 class YetMoreFun : public QObject
328 {
329 Q_OBJECT
330 public:
331 void funStuff();
332 };
333
334 }
335
336 namespace NameSchpace {
337
338 #define somevar 1
339
funStuff()340 void YetMoreFun::funStuff()
341 {
342 tr("funStuff!");
343 }
344
345 }
346
347
348
349 // QTBUG-27974: strings from included sources are not collected
350 #include "included.cpp"
351