1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:BSD$
|
---|
10 | ** You may use this file under the terms of the BSD license as follows:
|
---|
11 | **
|
---|
12 | ** "Redistribution and use in source and binary forms, with or without
|
---|
13 | ** modification, are permitted provided that the following conditions are
|
---|
14 | ** met:
|
---|
15 | ** * Redistributions of source code must retain the above copyright
|
---|
16 | ** notice, this list of conditions and the following disclaimer.
|
---|
17 | ** * Redistributions in binary form must reproduce the above copyright
|
---|
18 | ** notice, this list of conditions and the following disclaimer in
|
---|
19 | ** the documentation and/or other materials provided with the
|
---|
20 | ** distribution.
|
---|
21 | ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
|
---|
22 | ** the names of its contributors may be used to endorse or promote
|
---|
23 | ** products derived from this software without specific prior written
|
---|
24 | ** permission.
|
---|
25 | **
|
---|
26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
---|
30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
---|
31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
---|
32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
---|
36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
---|
37 | ** $QT_END_LICENSE$
|
---|
38 | **
|
---|
39 | ****************************************************************************/
|
---|
40 |
|
---|
41 | //! [0]
|
---|
42 | LoginWidget::LoginWidget()
|
---|
43 | {
|
---|
44 | QLabel *label = new QLabel(tr("Password:"));
|
---|
45 | ...
|
---|
46 | }
|
---|
47 | //! [0]
|
---|
48 |
|
---|
49 |
|
---|
50 | //! [1]
|
---|
51 | void some_global_function(LoginWidget *logwid)
|
---|
52 | {
|
---|
53 | QLabel *label = new QLabel(
|
---|
54 | LoginWidget::tr("Password:"), logwid);
|
---|
55 | }
|
---|
56 |
|
---|
57 | void same_global_function(LoginWidget *logwid)
|
---|
58 | {
|
---|
59 | QLabel *label = new QLabel(
|
---|
60 | qApp->translate("LoginWidget", "Password:"), logwid);
|
---|
61 | }
|
---|
62 | //! [1]
|
---|
63 |
|
---|
64 |
|
---|
65 | //! [2]
|
---|
66 | QString FriendlyConversation::greeting(int type)
|
---|
67 | {
|
---|
68 | static const char *greeting_strings[] = {
|
---|
69 | QT_TR_NOOP("Hello"),
|
---|
70 | QT_TR_NOOP("Goodbye")
|
---|
71 | };
|
---|
72 | return tr(greeting_strings[type]);
|
---|
73 | }
|
---|
74 | //! [2]
|
---|
75 |
|
---|
76 |
|
---|
77 | //! [3]
|
---|
78 | static const char *greeting_strings[] = {
|
---|
79 | QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
|
---|
80 | QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
|
---|
81 | };
|
---|
82 |
|
---|
83 | QString FriendlyConversation::greeting(int type)
|
---|
84 | {
|
---|
85 | return tr(greeting_strings[type]);
|
---|
86 | }
|
---|
87 |
|
---|
88 | QString global_greeting(int type)
|
---|
89 | {
|
---|
90 | return qApp->translate("FriendlyConversation",
|
---|
91 | greeting_strings[type]);
|
---|
92 | }
|
---|
93 | //! [3]
|
---|
94 |
|
---|
95 |
|
---|
96 | //! [4]
|
---|
97 | void FileCopier::showProgress(int done, int total,
|
---|
98 | const QString ¤tFile)
|
---|
99 | {
|
---|
100 | label.setText(tr("%1 of %2 files copied.\nCopying: %3")
|
---|
101 | .arg(done)
|
---|
102 | .arg(total)
|
---|
103 | .arg(currentFile));
|
---|
104 | }
|
---|
105 | //! [4]
|
---|
106 |
|
---|
107 |
|
---|
108 | //! [5]
|
---|
109 | QString s1 = "%1 of %2 files copied. Copying: %3";
|
---|
110 | QString s2 = "Kopierer nu %3. Av totalt %2 filer er %1 kopiert.";
|
---|
111 |
|
---|
112 | qDebug() << s1.arg(5).arg(10).arg("somefile.txt");
|
---|
113 | qDebug() << s2.arg(5).arg(10).arg("somefile.txt");
|
---|
114 | //! [5]
|
---|
115 |
|
---|
116 |
|
---|
117 | //! [6]
|
---|
118 | 5 of 10 files copied. Copying: somefile.txt
|
---|
119 | Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.
|
---|
120 | //! [6]
|
---|
121 |
|
---|
122 |
|
---|
123 | //! [7]
|
---|
124 | HEADERS = funnydialog.h \
|
---|
125 | wackywidget.h
|
---|
126 | SOURCES = funnydialog.cpp \
|
---|
127 | main.cpp \
|
---|
128 | wackywidget.cpp
|
---|
129 | FORMS = fancybox.ui
|
---|
130 | TRANSLATIONS = superapp_dk.ts \
|
---|
131 | superapp_fi.ts \
|
---|
132 | superapp_no.ts \
|
---|
133 | superapp_se.ts
|
---|
134 | //! [7]
|
---|
135 |
|
---|
136 |
|
---|
137 | //! [8]
|
---|
138 | int main(int argc, char *argv[])
|
---|
139 | {
|
---|
140 | QApplication app(argc, argv);
|
---|
141 |
|
---|
142 | QTranslator qtTranslator;
|
---|
143 | qtTranslator.load("qt_" + QLocale::system().name(),
|
---|
144 | QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
---|
145 | app.installTranslator(&qtTranslator);
|
---|
146 |
|
---|
147 | QTranslator myappTranslator;
|
---|
148 | myappTranslator.load("myapp_" + QLocale::system().name());
|
---|
149 | app.installTranslator(&myappTranslator);
|
---|
150 |
|
---|
151 | ...
|
---|
152 | return app.exec();
|
---|
153 | }
|
---|
154 | //! [8]
|
---|
155 |
|
---|
156 |
|
---|
157 | //! [9]
|
---|
158 | QString string = ...; // some Unicode text
|
---|
159 |
|
---|
160 | QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
|
---|
161 | QByteArray encodedString = codec->fromUnicode(string);
|
---|
162 | //! [9]
|
---|
163 |
|
---|
164 |
|
---|
165 | //! [10]
|
---|
166 | QByteArray encodedString = ...; // some ISO 8859-5 encoded text
|
---|
167 |
|
---|
168 | QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
|
---|
169 | QString string = codec->toUnicode(encodedString);
|
---|
170 | //! [10]
|
---|
171 |
|
---|
172 |
|
---|
173 | //! [11]
|
---|
174 | void Clock::setTime(const QTime &time)
|
---|
175 | {
|
---|
176 | if (tr("AMPM") == "AMPM") {
|
---|
177 | // 12-hour clock
|
---|
178 | } else {
|
---|
179 | // 24-hour clock
|
---|
180 | }
|
---|
181 | }
|
---|
182 | //! [11]
|
---|
183 |
|
---|
184 |
|
---|
185 | //! [12]
|
---|
186 | void MyWidget::changeEvent(QEvent *event)
|
---|
187 | {
|
---|
188 | if (e->type() == QEvent::LanguageChange) {
|
---|
189 | titleLabel->setText(tr("Document Title"));
|
---|
190 | ...
|
---|
191 | okPushButton->setText(tr("&OK"));
|
---|
192 | } else
|
---|
193 | QWidget::changeEvent(event);
|
---|
194 | }
|
---|
195 | //! [12]
|
---|