[844] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2011 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:FDL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
| 14 | ** written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Free Documentation License
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
| 18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
| 20 | ** file.
|
---|
| 21 | **
|
---|
| 22 | ** If you have questions regarding the use of this file, please contact
|
---|
| 23 | ** Nokia at qt-info@nokia.com.
|
---|
| 24 | ** $QT_END_LICENSE$
|
---|
| 25 | **
|
---|
| 26 | ****************************************************************************/
|
---|
| 27 |
|
---|
| 28 | /*!
|
---|
| 29 | \page qdeclarativei18n.html
|
---|
| 30 | \title QML Internationalization
|
---|
| 31 |
|
---|
| 32 | \section1 Overview
|
---|
| 33 |
|
---|
| 34 | Strings in QML can be marked for translation using the qsTr(), qsTranslate(),
|
---|
| 35 | QT_TR_NOOP(), and QT_TRANSLATE_NOOP() functions.
|
---|
| 36 |
|
---|
| 37 | For example:
|
---|
| 38 | \qml
|
---|
| 39 | Text { text: qsTr("Pictures") }
|
---|
| 40 | \endqml
|
---|
| 41 |
|
---|
| 42 | These functions are standard QtScript functions; for more details see
|
---|
| 43 | QScriptEngine::installTranslatorFunctions().
|
---|
| 44 |
|
---|
| 45 | QML relies on the core internationalization capabilities provided by Qt. These
|
---|
| 46 | capabilities are described more fully in:
|
---|
| 47 | \list
|
---|
| 48 | \o \l {Internationalization with Qt}
|
---|
| 49 | \o \l {Qt Linguist Manual}
|
---|
| 50 | \endlist
|
---|
| 51 |
|
---|
| 52 | You can test a translation with the \l {QML Viewer} using the -translation option.
|
---|
| 53 |
|
---|
| 54 | \section1 Example
|
---|
| 55 |
|
---|
| 56 | First we create a simple QML file with text to be translated. The string
|
---|
| 57 | that needs to be translated is enclosed in a call to \c qsTr().
|
---|
| 58 |
|
---|
| 59 | hello.qml:
|
---|
| 60 | \qml
|
---|
| 61 | import QtQuick 1.0
|
---|
| 62 |
|
---|
| 63 | Rectangle {
|
---|
| 64 | width: 200; height: 200
|
---|
| 65 | Text { text: qsTr("Hello"); anchors.centerIn: parent }
|
---|
| 66 | }
|
---|
| 67 | \endqml
|
---|
| 68 |
|
---|
| 69 | Next we create a translation source file using lupdate:
|
---|
| 70 | \code
|
---|
| 71 | lupdate hello.qml -ts hello.ts
|
---|
| 72 | \endcode
|
---|
| 73 |
|
---|
| 74 | Then we open \c hello.ts in \l{Qt Linguist Manual} {Linguist}, provide
|
---|
| 75 | a translation and create the release file \c hello.qm.
|
---|
| 76 |
|
---|
| 77 | Finally, we can test the translation:
|
---|
| 78 | \code
|
---|
| 79 | qmlviewer -translation hello.qm hello.qml
|
---|
| 80 | \endcode
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | You can see a complete example and source code in the \l{declarative/i18n}{QML Internationalization example}.
|
---|
| 84 | */
|
---|