source: trunk/doc/src/snippets/code/doc_src_i18n.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.2 KB
Line 
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]
42LoginWidget::LoginWidget()
43{
44 QLabel *label = new QLabel(tr("Password:"));
45 ...
46}
47//! [0]
48
49
50//! [1]
51void some_global_function(LoginWidget *logwid)
52{
53 QLabel *label = new QLabel(
54 LoginWidget::tr("Password:"), logwid);
55}
56
57void same_global_function(LoginWidget *logwid)
58{
59 QLabel *label = new QLabel(
60 qApp->translate("LoginWidget", "Password:"), logwid);
61}
62//! [1]
63
64
65//! [2]
66QString 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]
78static const char *greeting_strings[] = {
79 QT_TRANSLATE_NOOP("FriendlyConversation", "Hello"),
80 QT_TRANSLATE_NOOP("FriendlyConversation", "Goodbye")
81};
82
83QString FriendlyConversation::greeting(int type)
84{
85 return tr(greeting_strings[type]);
86}
87
88QString global_greeting(int type)
89{
90 return qApp->translate("FriendlyConversation",
91 greeting_strings[type]);
92}
93//! [3]
94
95
96//! [4]
97void FileCopier::showProgress(int done, int total,
98 const QString &currentFile)
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]
109QString s1 = "%1 of %2 files copied. Copying: %3";
110QString s2 = "Kopierer nu %3. Av totalt %2 filer er %1 kopiert.";
111
112qDebug() << s1.arg(5).arg(10).arg("somefile.txt");
113qDebug() << s2.arg(5).arg(10).arg("somefile.txt");
114//! [5]
115
116
117//! [6]
1185 of 10 files copied. Copying: somefile.txt
119Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.
120//! [6]
121
122
123//! [7]
124HEADERS = funnydialog.h \
125 wackywidget.h
126SOURCES = funnydialog.cpp \
127 main.cpp \
128 wackywidget.cpp
129FORMS = fancybox.ui
130TRANSLATIONS = superapp_dk.ts \
131 superapp_fi.ts \
132 superapp_no.ts \
133 superapp_se.ts
134//! [7]
135
136
137//! [8]
138int 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]
158QString string = ...; // some Unicode text
159
160QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
161QByteArray encodedString = codec->fromUnicode(string);
162//! [9]
163
164
165//! [10]
166QByteArray encodedString = ...; // some ISO 8859-5 encoded text
167
168QTextCodec *codec = QTextCodec::codecForName("ISO 8859-5");
169QString string = codec->toUnicode(encodedString);
170//! [10]
171
172
173//! [11]
174void 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]
186void 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]
Note: See TracBrowser for help on using the repository browser.