aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/qml-i18n/doc/src/i18n.qdoc
blob: 3ea56f651892b9b919208444db2a529f0a69ad48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
    \title Qt Quick I18N
    \example qml-i18n
    \image qml-i18n-example.png
    \ingroup examples-linguist
    \brief Generating translation files (TS and QM) for a Qt Quick application.

    When you run the example application, the QML runtime automatically loads a
    translation from the \c i18n subdirectory of the directory that contains the
    main .qml file, based on the system language.

    \section1 Marking Text as Translatable

    In the \c qml-i18n.qml file, use the \c qsTr command to mark UI text as
    translatable:

    \quotefromfile qml-i18n/qml-i18n.qml
    \skipto }
    \skipto Text
    \printuntil )

    \section1 Enabling Translation

    In the \c main.cpp file, use \l QQmlApplicationEngine to automatically load
    translation files from a subdirectory called \c i18n in the directory that
    contains the main QML file:

    \quotefromfile qml-i18n/main.cpp
    \skipto <QQmlApplicationEngine>
    \printuntil engine;

    The translation file names in the \c i18n subdirectory must have the prefix
    \c qml_. For example, \c qml_en_AU.ts.

    \section1 Creating Translation Files

    Add the \c LinguistTools module as a value of the \c find_package command in
    the \c CMakeLists.txt file:

    \quotefromfile qml-i18n/CMakeLists.txt
    \skipto find_package(
    \printuntil )

    Define the translation files to generate in the \l qt_add_translations
    command:

    \skipto qt_add_translations
    \printuntil )

    Build the application to generate TS and QM files.

    \note On Android, make sure to include the QM files as resources.

    \section1 Adding Translations

    To create translations for new languages, copy \e {i18n/base.ts} to
    \e {i18n/qml_<lang>.ts}. You can use \l{Qt Linguist} to translate the
    strings.
*/