|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the documentation of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 //! [0] |
|
43 LoginWidget::LoginWidget() |
|
44 { |
|
45 QLabel *label = new QLabel(tr("Password:")); |
|
46 ... |
|
47 } |
|
48 //! [0] |
|
49 |
|
50 |
|
51 //! [1] |
|
52 void some_global_function(LoginWidget *logwid) |
|
53 { |
|
54 QLabel *label = new QLabel( |
|
55 LoginWidget::tr("Password:"), logwid); |
|
56 } |
|
57 |
|
58 void same_global_function(LoginWidget *logwid) |
|
59 { |
|
60 QLabel *label = new QLabel( |
|
61 qApp->translate("LoginWidget", "Password:"), logwid); |
|
62 } |
|
63 //! [1] |
|
64 |
|
65 |
|
66 //! [2] |
|
67 QString FriendlyConversation::greeting(int type) |
|
68 { |
|
69 static const char *greeting_strings[] = { |
|
70 QT_TR_NOOP("Hello"), |
|
71 QT_TR_NOOP("Goodbye") |
|
72 }; |
|
73 return tr(greeting_strings[type]); |
|
74 } |
|
75 //! [2] |
|
76 |
|
77 |
|
78 //! [3] |
|
79 static const char *greeting_strings[] = { |
|
80 QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"), |
|
81 QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye") |
|
82 }; |
|
83 |
|
84 QString FriendlyConversation::greeting(int type) |
|
85 { |
|
86 return tr(greeting_strings[type]); |
|
87 } |
|
88 |
|
89 QString global_greeting(int type) |
|
90 { |
|
91 return qApp->translate("FriendlyConversation", |
|
92 greeting_strings[type]); |
|
93 } |
|
94 //! [3] |
|
95 |
|
96 |
|
97 //! [4] |
|
98 void FileCopier::showProgress(int done, int total, |
|
99 const QString ¤tFile) |
|
100 { |
|
101 label.setText(tr("%1 of %2 files copied.\nCopying: %3") |
|
102 .arg(done) |
|
103 .arg(total) |
|
104 .arg(currentFile)); |
|
105 } |
|
106 //! [4] |
|
107 |
|
108 |
|
109 //! [5] |
|
110 QString s1 = "%1 of %2 files copied. Copying: %3"; |
|
111 QString s2 = "Kopierer nu %3. Av totalt %2 filer er %1 kopiert."; |
|
112 |
|
113 qDebug() << s1.arg(5).arg(10).arg("somefile.txt"); |
|
114 qDebug() << s2.arg(5).arg(10).arg("somefile.txt"); |
|
115 //! [5] |
|
116 |
|
117 |
|
118 //! [6] |
|
119 5 of 10 files copied. Copying: somefile.txt |
|
120 Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert. |
|
121 //! [6] |
|
122 |
|
123 |
|
124 //! [7] |
|
125 HEADERS = funnydialog.h \ |
|
126 wackywidget.h |
|
127 SOURCES = funnydialog.cpp \ |
|
128 main.cpp \ |
|
129 wackywidget.cpp |
|
130 FORMS = fancybox.ui |
|
131 TRANSLATIONS = superapp_dk.ts \ |
|
132 superapp_fi.ts \ |
|
133 superapp_no.ts \ |
|
134 superapp_se.ts |
|
135 //! [7] |
|
136 |
|
137 |
|
138 //! [8] |
|
139 int main(int argc, char *argv[]) |
|
140 { |
|
141 QApplication app(argc, argv); |
|
142 |
|
143 QTranslator qtTranslator; |
|
144 qtTranslator.load("qt_" + QLocale::system().name(), |
|
145 QLibraryInfo::location(QLibraryInfo::TranslationsPath)); |
|
146 app.installTranslator(&qtTranslator); |
|
147 |
|
148 QTranslator myappTranslator; |
|
149 myappTranslator.load("myapp_" + QLocale::system().name()); |
|
150 app.installTranslator(&myappTranslator); |
|
151 |
|
152 ... |
|
153 return app.exec(); |
|
154 } |
|
155 //! [8] |
|
156 |
|
157 |
|
158 //! [9] |
|
159 QString string = ...; // some Unicode text |
|
160 |
|
161 QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5"); |
|
162 QByteArray encodedString = codec->fromUnicode(string); |
|
163 //! [9] |
|
164 |
|
165 |
|
166 //! [10] |
|
167 QByteArray encodedString = ...; // some ISO 8859-5 encoded text |
|
168 |
|
169 QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5"); |
|
170 QString string = codec->toUnicode(encodedString); |
|
171 //! [10] |
|
172 |
|
173 |
|
174 //! [11] |
|
175 void Clock::setTime(const QTime &time) |
|
176 { |
|
177 if (tr("AMPM") == "AMPM") { |
|
178 // 12-hour clock |
|
179 } else { |
|
180 // 24-hour clock |
|
181 } |
|
182 } |
|
183 //! [11] |
|
184 |
|
185 |
|
186 //! [12] |
|
187 void QWidget::changeEvent(QEvent *event) |
|
188 { |
|
189 if (e->type() == QEvent::LanguageChange) { |
|
190 titleLabel->setText(tr("Document Title")); |
|
191 ... |
|
192 okPushButton->setText(tr("&OK")); |
|
193 } else |
|
194 QWidget::changeEvent(event); |
|
195 } |
|
196 //! [12] |