summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeena Miettinen <riitta-leena.miettinen@qt.io>2023-01-24 09:43:17 +0100
committerLeena Miettinen <riitta-leena.miettinen@qt.io>2023-01-27 12:35:29 +0000
commitaca0147902bcfffa22d0d707ab351a57d8787ec3 (patch)
tree5d7144a7ba4e11a2b6ac5ea575d5635ca5923483
parent5106799c3e3d041e78049ad52afa6dc35ffc6c32 (diff)
downloadqtdoc-aca0147902bcfffa22d0d707ab351a57d8787ec3.tar.gz
Doc: Consolidate internationalization documentation
- Combine the "Internationalization with Qt" and "Internationalization and Localization with Qt Quick" topics - Add a "Localizing Applications" topic - Move information from the Qt Linguist Manual developer section to the new topics - Add a link to a YouTube video about localizing apps - Use active voice and present tense Fixes: QTBUG-71876 Change-Id: If2db1d4865e47a85e0b63adac326fc123ad65e50 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Kai Köhne <kai.koehne@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit bdf675dbd6f31917f4cc4637d799b12137f17167)
-rw-r--r--doc/config/images/xNIz78IPBu0.jpgbin0 -> 1675 bytes
-rw-r--r--doc/config/qtdoc.qdocconf3
-rw-r--r--doc/src/developmenttools.qdoc19
-rw-r--r--doc/src/internationalization/i18n.qdoc1262
-rw-r--r--doc/src/internationalization/l10n.qdoc248
-rw-r--r--doc/src/qmlapp/internationalization.qdoc272
-rw-r--r--doc/src/qmlapp/usecases/text.qdoc2
-rw-r--r--doc/src/snippets/code/doc_src_i18n.cpp21
-rw-r--r--doc/src/snippets/code/doc_src_i18n.qdoc6
-rw-r--r--doc/src/snippets/code/src_corelib_kernel_qobject.cpp9
10 files changed, 966 insertions, 876 deletions
diff --git a/doc/config/images/xNIz78IPBu0.jpg b/doc/config/images/xNIz78IPBu0.jpg
new file mode 100644
index 00000000..cabc31e5
--- /dev/null
+++ b/doc/config/images/xNIz78IPBu0.jpg
Binary files differ
diff --git a/doc/config/qtdoc.qdocconf b/doc/config/qtdoc.qdocconf
index fece4d5b..2e8662b8 100644
--- a/doc/config/qtdoc.qdocconf
+++ b/doc/config/qtdoc.qdocconf
@@ -66,7 +66,8 @@ qhp.QtDoc.subprojects.examples.sortPages = true
{HTML.extraimages,DocBook.extraimages,qhp.QtDoc.extraFiles} += images/qt-codesample.png \
images/yIv0vO8B7tQ.jpg \
images/5OiIqFTjUZI.jpg \
- images/nmvurCcsWos.jpg
+ images/nmvurCcsWos.jpg \
+ images/xNIz78IPBu0.jpg
# Add an .html file with sidebar content, used in the online style
HTML.stylesheets += style/qt5-sidebar.html
diff --git a/doc/src/developmenttools.qdoc b/doc/src/developmenttools.qdoc
index 9c61e24b..df22dec7 100644
--- a/doc/src/developmenttools.qdoc
+++ b/doc/src/developmenttools.qdoc
@@ -62,7 +62,7 @@
Meson, and IncrediBuild projects.
For more information about project templates and building in Qt Creator,
- visit the following pages:
+ see:
\list
\li \l{Qt Creator: Build Systems}
\li \l{Qt Creator: Building for Multiple Platforms}
@@ -76,7 +76,7 @@
different targets. The \l{Qt Platform Abstraction} is an abstraction
layer to facilitate Qt ports onto different platforms and targets.
- For more information about building Qt, visit the following pages:
+ For more information about building Qt, see:
\list
\li \l{Build with CMake}
\li \l{qmake Manual}
@@ -87,20 +87,17 @@
\section1 Internationalization and Help Tools
- You can localize your application to different languages. There is an
- \l{Internationalization with Qt}{internationalization} framework within Qt
+ You can localize your application to different languages. Use the Qt
+ \l{Internationalization with Qt}{internationalization} framework
for handling different writing systems, translating interfaces, and for
displaying numbers, dates, and currency in different formats.
- \l{Qt Linguist Manual}{Qt Linguist} is a tool for developers, translators,
- and release managers to implement internationalization in applications.
- The different roles can collaborate to produce, store, and deploy translated
- text in the user interface.
+ \l{Qt Linguist Manual}{Qt Linguist} is a tool for translators for
+ translating applications. Together with release managers and developers,
+ they produce, store, and deploy translated text in the UI.
- For more information about internationalization and localization, visit
- these pages:
+ For more information about internationalization and localization, see:
\list
\li \l{Internationalization with Qt}
- \li \l{Internationalization and Localization with Qt Quick}
\li \l{Qt Linguist Manual}{Qt Linguist}
\li \l{Writing Source Code for Translation}
\endlist
diff --git a/doc/src/internationalization/i18n.qdoc b/doc/src/internationalization/i18n.qdoc
index e6ba3102..22ae937d 100644
--- a/doc/src/internationalization/i18n.qdoc
+++ b/doc/src/internationalization/i18n.qdoc
@@ -1,19 +1,10 @@
-// Copyright (C) 2020 The Qt Company Ltd.
+// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
- \group i18n
- \brief How to internationalize your Qt application.
- \title Qt Classes for Internationalization
-
- See \l{Internationalization with Qt} for information on how to use these classes
- in your applications.
-*/
-
-/*!
\group internationalization
\title Internationalization with Qt
- \brief Information about Qt's support for internationalization and multiple languages.
+ \brief Qt's support for internationalization and multiple languages.
\nextpage Writing Source Code for Translation
@@ -22,284 +13,155 @@
The \e internationalization and \e localization of an application are the
processes of adapting the application to different languages, regional
- differences and technical requirements of a target market.
- Internationalization means designing a software application so that it can
- be adapted to various languages and regions without engineering changes.
- Localization means adapting internationalized software for a specific region
- or language by adding locale-specific components (such as date, time, and
- number formats) and translating text.
-
- \tableofcontents
-
- \section1 Relevant Qt Classes and APIs
-
- These classes support internationalizing of Qt applications.
-
- \annotatedlist i18n
-
- \section1 Languages and Writing Systems
-
- In some cases internationalization is simple, for example, making a US
- application accessible to Australian or British users may require
- little more than a few spelling corrections. But to make a US
- application usable by Japanese users, or a Korean application usable
- by German users, will require that the software operate not only in
- different languages, but use different input techniques, character
- encoding and presentation conventions.
-
- Qt tries to make internationalization as painless as possible for
- developers. All input controls and text drawing methods in Qt offer
- built-in support for all supported languages. The built-in font engine
- is capable of correctly and attractively rendering text that contains
- characters from a variety of different writing systems at the same
- time.
-
- Qt supports most languages in use today, in particular:
- \list
- \li All East Asian languages (Chinese, Japanese and Korean)
- \li All Western languages (using Latin script)
- \li Arabic
- \li Cyrillic languages (Russian, Ukrainian, etc.)
- \li Greek
- \li Hebrew
- \li Thai and Lao
- \li All scripts in Unicode 6.2 that do not require special processing
- \li Bengali
- \li Burmese (Myanmar)
- \li Devanagari
- \li Gujarati
- \li Gurmukhi
- \li Kannada
- \li Khmer
- \li Malayalam
- \li Tamil
- \li Telugu
- \li Tibetan
- \endlist
-
- The list above is supported and will work on all platforms as long as
- the system has fonts to render these writing systems installed.
+ differences, and technical requirements of a target market.
- On Windows, Linux and Unix with FontConfig (client side font support)
- the following languages are also supported:
\list
- \li Dhivehi (Thaana)
- \li Syriac
- \li N'Ko
+ \li \l {Writing Source Code for Translation}{Internationalization}
+ means designing an application so that it can be adapted to various
+ languages and regions without engineering changes.
+ \li \l {Localizing Applications}{Localization} means adapting
+ internationalized applications for a specific region or language by
+ adding locale-specific components (such as date, time, and number
+ formats) and translating text.
\endlist
- On \macos, the following languages are also supported:
- \list
- \li Oriya
- \li Sinhala
- \endlist
+ The need for internationalization ranges from spelling changes to enabling
+ the application to operate in different languages and to use different input
+ techniques, character encoding, and presentation conventions.
- Many of these writing systems exhibit special features:
+ All input controls and text drawing methods in Qt offer built-in support for
+ all supported languages. The built-in font engine correctly renders text that
+ contains characters from a variety of different writing systems at the same
+ time.
- \list
+ \table
+ \header
+ \li For more information about
+ \li See
+ \row
+ \li Internationalizing source code
+ \li \l{Writing Source Code for Translation}
+ \row
+ \li Configuring and deploying translations, as well as using existing
+ Qt module translations
+ \li \l {Localizing Applications}
+ \row
+ \li Using the Qt translation tools
+ \li \l {Qt Linguist Manual}
+ \endtable
- \li \b{Special line breaking behavior.} Some of the Asian languages are
- written without spaces between words. Line breaking can occur either
- after every character (with exceptions) as in Chinese, Japanese and
- Korean, or after logical word boundaries as in Thai.
+ The following video shows how to internationalize and localize a simple
+ example application:
- \li \b{Bidirectional writing.} Arabic and Hebrew are written from right to
- left, except for numbers and embedded English text which is written
- left to right. The exact behavior is defined in the
- \l{https://www.unicode.org/unicode/reports/tr9/}{Unicode Technical Annex #9}.
+ \youtube xNIz78IPBu0
- \li \b{Non-spacing or diacritical marks (accents or umlauts in European
- languages).} Some languages such as Vietnamese make extensive use of
- these marks and some characters can have more than one mark at the
- same time to clarify pronunciation.
+ \section1 Qt Classes for Internationalization
- \li \b{Ligatures.} In special contexts, some pairs of characters get
- replaced by a combined glyph forming a ligature. Common examples are
- the fl and fi ligatures used in typesetting US and European books.
+ The following classes support internationalizing of Qt applications.
- \endlist
+ \annotatedlist i18n
- Qt tries to take care of all the special features listed above. You
- usually don't have to worry about these features so long as you use
- Qt's input controls (e.g. QLineEdit, QTextEdit, and derived classes
- or the Quick TextInput item) and Qt's display controls (e.g. QLabel
- and Qt Quick's Text item).
-
- Support for these writing systems is transparent to the
- programmer and completely encapsulated in \l{Rich Text Processing}{Qt's text engine}.
- This means that you don't usually need to have any knowledge of the writing
- system used in a particular language, unless you want to write your own text
- input controls. In some languages, such as Arabic or languages from the
- Indian subcontinent, the width and shape of a glyph changes depending on the
- surrounding characters. To take this into account, use QTextLayout.
- Writing input controls also requires some knowledge of the scripts they are
- going to be used in. Usually, the easiest way is to subclass QLineEdit or
- QTextEdit.
+ See \l{Writing Source Code for Translation} for more information about how
+ to use the classes in applications.
- For more information about how to internationalize source code, see
- \l{Writing Source Code for Translation} and
- \l{Internationalization and Localization with Qt Quick}.
+ \section1 Languages and Writing Systems
- \section1 Producing Translations
+ Qt supports most \l {QLocale::Language}{languages} in use today.
- Qt provides excellent support for translating Qt C++ and Qt Quick
- applications into local languages. Release managers, translators, and
- developers can use the Qt translation tools to accomplish their tasks.
+ Input controls, such as the Qt Quick TextInput type and QLineEdit, QTextEdit,
+ and derived classes, as well as display controls, such as the \l Text type
+ and QLabel class handle the following special features of the different
+ writing systems:
- The Qt translation tools, Qt Linguist, \c lupdate, and \c lrelease are
- installed in the \c bin subdirectory of the base directory Qt is installed
- into. For more information about using them, see the \l{Qt Linguist Manual}.
+ \list
- \target qt-itself
- Qt itself contains several thousands of strings that will also need to be
- translated into the languages that you are targeting. You will find
- a number of translation files in the qttranslations repository.
- Before you start translating Qt, read the wiki page
- \l{external: Translating Qt Into Other Languages}
- {Translating Qt Into Other Languages}.
+ \li Line breaks
- \section1 Enabling Translation
+ Some of the Asian languages are
+ written without spaces between words. Line breaking can occur either
+ after any character (with exceptions) as in Chinese, Japanese and
+ Korean, or after logical word boundaries as in Thai.
- Typically, your application's \c main() function will look like
- this:
+ \li Bidirectional writing
- \snippet snippets/code/doc_src_i18n.cpp 8
+ Arabic and Hebrew are written from right to
+ left, except for numbers and embedded English text which is written
+ left to right. The exact behavior is defined in the
+ \l{https://www.unicode.org/unicode/reports/tr9/}{Unicode Technical Annex #9}.
- For a translation-aware application, a QTranslator object is created, then a
- translation is loaded according to the user's preferred UI display locale at
- runtime, and finally, the translator object is installed into the
- application.
+ \li Non-spacing or diacritical marks, such as accents or umlauts in European
+ languages
- \section1 Locating Qt Translations
+ Some languages, such as Vietnamese, make extensive use of
+ these marks and some characters can have more than one mark at the
+ same time to clarify pronunciation.
- You can also use QLibraryInfo::path() to locate the translations for the
- Qt modules used. You can request the path to the translations at run-time by
- passing QLibraryInfo::TranslationsPath to this function.
+ \li Ligatures
- \section2 Available Catalogs
+ In special contexts, some pairs of characters get
+ replaced by a combined glyph forming a ligature. Common examples are
+ the \c fl and \c fi ligatures used in typesetting US and European books.
- The Qt translation catalogs are located in the \c qttranslations repository.
+ \endlist
- \warning Qt translations are contributed by the Qt community, and provided
- without any guarantees. Translations might be missing, outdated, or entirely
- incorrect, up to the point of being malicious. It is recommended that you
- audit any translations you ship.
+ \l{Rich Text Processing}{Qt's text engine} supports different
+ \l {QLocale::Script}{writing systems} that work on all platforms
+ if the fonts for rendering them are installed.
- The \c qt_ meta catalog contains the still-existing Qt translations that
- were included in the \c qt_ catalog in Qt 4. It was created to make porting
- applications from Qt 4 to Qt 5 easier. The meta catalog depends on
- translations that might be absent, because they belong to unnecessary or
- deprecated modules, which might cause the loading of the translations to
- fail. If you use modules that are new in Qt 5 or later in your application,
- you must specify the names of the catalogs for those modules even if you
- use the meta catalog.
+ You do not need to know about the writing system used in a particular
+ language, unless you want to write your own text input controls. In some
+ languages, such as Arabic or languages from the
+ Indian subcontinent, the width and shape of a glyph changes depending on the
+ surrounding characters. To take this into account in C++ code, use QTextLayout.
+ Writing input controls also requires some knowledge of the scripts they are
+ going to be used in. Usually, the easiest way is to subclass QLineEdit or
+ QTextEdit.
- The following table lists the translation catalogs available for the Qt
- modules and tools in Qt.
+ \section1 Encoding
- \table
- \header
- \li Qt Module or Tool
- \li Catalog
- \row
- \li \c {Qt Bluetooth}
- \li \c qtconnectivity
- \row
- \li \l [QtConcurrent]{Qt Concurrent}
- \li \c qtbase
- \row
- \li \l [QtCore]{Qt Core}
- \li \c qtbase
- \row
- \li \l [QtDBus]{Qt D-Bus}
- \li \c qtbase
- \row
- \li \l {Qt Designer}
- \li \c designer
- \row
- \li \l [QtGui]{Qt GUI}
- \li \c qtbase
- \row
- \li \l {Qt Help}
- \li \c qt_help
- \row
- \li \l {Qt Linguist Manual}{Qt Linguist}
- \li \c linguist
- \row
- \li \l[Qt Network]{Qt Network}
- \li \c qtbase
- \row
- \li \c {Qt NFC}
- \li \c qtconnectivity
- \row
- \li \l [QtPrintSupport]{Qt Print Support}
- \li \c qtbase
- \row
- \li \l {Qt QML}
- \li \c qtdeclarative
- \row
- \li \l {Qt Quick}
- \li \c qtdeclarative
- \row
- \li \l {Qt Quick Controls}
- \li \c qtdeclarative
- \row
- \li \l {Qt Quick Widgets C++ Classes}{Qt Quick Widgets}
- \li \c qtdeclarative
- \row
- \li \c {Qt SerialPort}
- \li \c qtserialport
- \row
- \li \l [QtSql]{Qt SQL}
- \li \c qtbase
- \row
- \li \l [QtWidgets]{Qt Widgets}
- \li \c qtbase
- \row
- \li \c {Qt WebSockets}
- \li \c qtsockets
- \row
- \li \c {Qt WebEngine}
- \li \c qtwebengine
- \endtable
+ Encoding is relevant both for application source files and the text files
+ that the application reads or writes.
- \section2 Example: Basic Qt Modules
+ \section2 Encoding Source Code
- For example, to locate translations for basic Qt modules, such as Qt Core,
- Qt GUI, Qt Network, and Qt Widgets, add the following code to the \c main()
- function:
+ QML documents are always encoded in UTF-8 format. Since Qt 6, 8-bit
+ \l{http://www.ietf.org/rfc/rfc2279.txt}{UTF-8} is the predominant encoding
+ also in Qt C++.
- \snippet snippets/code/doc_src_i18n.cpp 14
+ The \c lupdate tool extracts UI strings from your application.
+ It expects all source code to be encoded in UTF-8 by default.
- \section1 Support for Encodings
+ However, some editors, such as Visual Studio, use a different
+ encoding by default. One way to avoid encoding issues is to limit any
+ source code to ASCII, and use escape sequences for translatable strings
+ with other characters, for example:
- As of Qt 6, it is assumed that 8-bit
- \l{http://www.ietf.org/rfc/rfc2279.txt}{UTF-8} is the predominant encoding.
+ \code
+ label->setText(tr("F\374r \310lise"));
+ \endcode
- QString::toUtf8() returns the text in UTF-8 encoding; this perfectly
- preserves Unicode information while looking like plain ASCII if the text
- is wholly ASCII.
+ QString::toUtf8() returns the text in UTF-8 encoding, which preserves
+ \l{Unicode in Qt}{Unicode} information while looking like plain ASCII if
+ the text is wholly ASCII. To convert Unicode to local 8-bit encoding, use
+ QString::toLocal8Bit(). On Unix systems, this is equivalent to \c toUtf8().
+ On Windows, the system's current code page is used.
- For converting Unicode to local 8-bit encoding, a shortcut is
- available: the QString::toLocal8Bit() function returns such 8-bit
- data. On Unix systems this is equivalent to toUtf8(), on Windows the
- systems current code page is being used.
+ For converting from UTF-8 and local 8-bit encoding to Unicode, use the
+ QString::fromUtf8() and QString::fromLocal8Bit() convenience functions.
- For converting the other way, there are the QString::fromUtf8() and
- QString::fromLocal8Bit() convenience functions.
+ \section2 Encoding Text Input/Output
- For QTextStream, QTextStream::setEncoding() can be used to set
- common encodings.
+ Use QTextStream::setEncoding() to set common encoding for text streams.
- Should other legacy encodings be required, the QTextCodec class from the
- Qt5Compat module can be used.
+ If you need some other legacy encoding, use the QTextCodec class from the
+ Qt5Compat module.
- When an application starts, the locale of the machine will determine the 8-bit
- encoding used when dealing with external 8-bit data. QTextCodec::codecForLocale()
- returns a codec that can be used to convert between this locale encoding
+ When an application starts, the locale of the machine determines the 8-bit
+ encoding used for external 8-bit data. QTextCodec::codecForLocale()
+ returns a codec that you can use to convert between this locale encoding
and Unicode.
- The application may occasionally require encodings other than the
+ The application may occasionally require encoding other than the
default local 8-bit encoding. For example, an application in a
Cyrillic KOI8-R locale (the de-facto standard locale in Russia) might
need to output Cyrillic in the ISO 8859-5 encoding. Code for this
@@ -307,58 +169,15 @@
\snippet snippets/code/doc_src_i18n.cpp 9
- For converting the other way, the below code demonstrates the conversion
- from ISO 8859-5 Cyrillic to Unicode:
+ The following code demonstrates the conversion from ISO 8859-5 Cyrillic to
+ Unicode:
\snippet snippets/code/doc_src_i18n.cpp 10
For a complete list of supported encodings see the \l QTextCodec
documentation.
- \keyword localization
-
- \section1 Localizing Numbers, Dates, Times and Currency
-
- Localization is the process of adapting to local conventions, for
- example presenting dates and times using the locally preferred
- formats. For localized numbers, dates, times and currency strings, use the
- QLocale class.
-
- Localizing images is not recommended. Choose clear icons that are
- appropriate for all localities, rather than relying on local puns or
- stretched metaphors. The exception is for images of left and right
- pointing arrows which may need to be reversed for Arabic and Hebrew
- locales.
-
- \section1 Dynamic Translation
-
- Some applications, such as Qt Linguist, must be able to support changes
- to the user's language settings while they are still running. To make
- widgets aware of changes to the installed QTranslator objects, reimplement the
- widget's \l{QWidget::changeEvent()}{changeEvent()} function to check whether
- the event is a \l{QEvent::LanguageChange}{LanguageChange} event, and update
- the text displayed by widgets using the \l{QObject::tr()}{tr()} function
- in the usual way. For example:
-
- \snippet snippets/code/doc_src_i18n.cpp 12
-
- All other change events should be passed on by calling the default
- implementation of the function.
-
- The list of installed translators might change in reaction to a
- \l{QEvent::LocaleChange}{LocaleChange} event, or the application might
- provide a user interface that allows the user to change the current
- application language.
-
- The default event handler for QWidget subclasses responds to the
- QEvent::LanguageChange event, and will call this function when necessary.
-
- \l{QEvent::LanguageChange}{LanguageChange} events are posted when a new
- translation is installed using the QCoreApplication::installTranslator()
- function. Additionally, other application components can also force
- widgets to update themselves by posting LanguageChange events to them.
-
- \section1 System Support
+ \section1 Operating and Windowing Systems
Some of the operating systems and windowing systems that Qt runs on
only have limited support for Unicode. The level of support available
@@ -369,45 +188,41 @@
\section2 Unix/X11
\list
- \li Locale-oriented fonts and input methods. Qt hides these and
+ \li Qt hides locale-oriented fonts and input methods and
provides Unicode input and output.
- \li Filesystem conventions such as UTF-8
- are today used by default in most Unix variants. All Qt file
- functions allow Unicode, but convert filenames to the local
- 8-bit encoding, as this is the Unix convention (see
- QFile::setEncodingFunction() to explore alternative
- encodings).
+ \li Most Unix variants use filesystem conventions such as UTF-8
+ by default. All Qt file functions allow Unicode, but convert
+ filenames to the local 8-bit encoding, as this is the Unix convention.
\li File I/O defaults to the local 8-bit encoding,
with Unicode options in QTextStream.
\li Some older Unix distributions contain only partial support for some locales.
- For example, if you have a \c /usr/share/locale/ja_JP.EUC directory,
- this does not necessarily mean you can display Japanese text; you also
- need to have Japanese fonts installed, and the
- \c /usr/share/locale/ja_JP.EUC directory needs to be complete. For
- best results, use complete locales from your system vendor.
+ For example, even if you have a \c /usr/share/locale/ja_JP.EUC directory,
+ you cannot display Japanese text unless you install Japanese fonts and
+ the directory is complete. For best results, use complete locales from
+ your system vendor.
\endlist
\section2 Linux
\list
\li Qt provides full Unicode support, including input methods, fonts,
- clipboard, drag-and-drop.
- \li The file system is usually encoded in UTF-8 on all modern Linux
- distributions and should not pose a problem. File I/O defaults to UTF-8.
+ clipboard, and drag-and-drop.
+ \li The file system is encoded in UTF-8 on all modern Linux distributions.
+ File I/O defaults to UTF-8.
\endlist
\section2 Windows
\list
\li Qt provides full Unicode support, including input methods, fonts,
- clipboard, drag-and-drop and file names.
+ clipboard, drag-and-drop, and file names.
\li File I/O defaults to Latin1, with Unicode options in QTextStream.
- Note that some Windows programs do not understand big-endian
+ However, some Windows programs do not understand big-endian
Unicode text files even though that is the order prescribed by
- the Unicode Standard in the absence of higher-level protocols.
+ the Unicode standard in the absence of higher-level protocols.
\endlist
- \section1 Related Pages
+ \section1 Related Topics
*/
/*!
@@ -415,370 +230,709 @@
\title Writing Source Code for Translation
\ingroup internationalization
\previouspage Internationalization with Qt
- \nextpage Translation Rules for Plurals
- \brief How to write source code in a way that makes it possible for user-visible text to be translated.
+ \nextpage Localizing Applications
+ \brief Writing source code that enables the localization of applications.
- \tableofcontents
+ Write QML and Qt C++ source code in a way that enables you to localize
+ applications:
- Writing cross-platform international software with Qt is a gentle,
- incremental process. Your software can become internationalized in
- the stages described in the following sections.
- For more information about internalizing Qt Quick application, see
- \l{Internationalization and Localization with Qt Quick}.
+ \list
+ \li \l {Mark Strings for Translation}
+ \li \l {Use Parameters Instead of Concatenating Strings}
+ \li \l {Handle Plural Forms}
+ \li \l {Use Regional Number Settings}
+ \li \l {Internationalize Date, Time, and Currency}
+ \li \l {Mark Translatable Data Text Strings}
+ \li \l {Add Comments for Translators}
+ \li \l {Disambiguate Identical Text}
+ \li \l {Make Keyboard Shortcuts Translatable}
+ \li \l {Use Locale to Extend Localization Features}
+ \li \l {Enable Translation}
+ \endlist
- \section1 Using QString for All User-Visible Text
+ When developing C++ applications, see also
+ \l {Additional Considerations for C++ Code}.
- Since QString uses the Unicode encoding internally, every
- language in the world can be processed transparently using
- familiar text processing operations. Also, since all Qt functions
- that present text to the user take a QString as a parameter,
- there is no \c{char *} to QString conversion overhead.
+ \section1 Mark Strings for Translation
+
+ Most of the text that must be translated in an application consists of
+ either single words or short phrases. These typically appear as window
+ titles, menu items, tooltips, and labels to buttons, check boxes, and
+ radio buttons.
+
+ Qt minimizes the performance cost of using translations by
+ translating the phrases for each window as they are created. In most
+ applications, the main window is created just once. Dialogs are often
+ created once and then shown and hidden as required. Once the initial
+ translation has taken place, there is no further runtime overhead for
+ the translated windows. Only those windows that are created,
+ destroyed and subsequently created will have a translation
+ performance cost.
- Strings that are in "programmer space" (such as QObject names
- and file format texts) need not use QString; the traditional
- \c{char *} or the QByteArray class will suffice.
+ You can create applications that switch language at runtime, but it
+ requires an effort and comes with a runtime performance cost.
- You're unlikely to notice that you are using Unicode;
- QString, and QChar are just easier versions of the crude
- \c{const char *} and \c char from traditional C.
+ Use translation functions to mark user-visible UI text for
+ translation in QML and C++ code. Qt indexes each translatable string by
+ the \e{translation context} it is associated with.
+ The same phrase may occur in more than one context without conflict.
+ If a phrase occurs more than once in a particular context, it is translated
+ only once and the translation is applied to every occurrence within the
+ context.
- \c{char *} strings in source code are assumed to be
- \l{http://www.ietf.org/rfc/rfc2279.txt}{UTF-8} encoded when being
- implicitly converted to a QString. If your C string literal
- uses a different encoding, use QString::fromLatin1() or QTextCodec
- to convert the literal to a Unicode encoded QString.
+ \section2 QML: Use qsTr()
- \section1 Using tr() for All Literal Text
+ In QML, the translation context is the QML type name.
+
+ You can use the following functions to mark user-visible strings for
+ translation in .qml files:
+
+ \list
+ \li \l [QML] {Qt::}{qsTr()}
+ \li \l [QML] {Qt::}{qsTranslate()}
+ \li \l [QML] {Qt::}{qsTrId()}
+ \endlist
- Wherever your program uses a string literal (quoted text) that will
- be presented to the user, ensure that it is processed by the \l
- QCoreApplication::translate() function. Essentially all that is necessary
- to achieve this is to use the \l{QObject::}{tr()} function to obtain
- translated text for your classes, typically for display purposes. This
- function is also used to indicate which text strings in an application are
- translatable.
+ Usually, you use the \c qsTr() function:
+
+ \code
+ Text {
+ id: txt1
+ text: qsTr("Back")
+ }
+ \endcode
+
+ This code makes \e Back a key entry in the translation source (TS) files. At
+ runtime, the translation system looks up the keyword \e Back and then
+ gets the corresponding translation value for the current system locale.
+ The result is returned to the \c text property and the UI shows the
+ appropriate translation of \e Back for the current locale. If no translation
+ is found, \c qsTr() returns the original string.
+
+ \section2 C++: Use tr()
+
+ In C++, use the \l{QObject::}{tr()} function to mark text as translatable
+ and to display translated text. The translation context is the name of the
+ QObject subclass the string is used in. To define translation context for new
+ QObject-based classes, use the Q_OBJECT macro in each new class definition.
+
+ When \c tr() is called, it looks up the translatable string using a
+ \l QTranslator object, which you must install on the application object,
+ as described in \l{Enable Translation}.
For example, assuming the \c LoginWidget is a subclass of QWidget:
\snippet snippets/code/doc_src_i18n.cpp 0
This accounts for 99% of the user-visible strings you're likely to
- write.
+ write. For information about marking string literals translatable,
+ see \l {Mark Translatable Data Text Strings}.
- If the quoted text is not in a member function of a
- QObject subclass, use either the tr() function of an
- appropriate class, or the QCoreApplication::translate() function
- directly:
+ If the quoted text is not in a member function of a QObject subclass,
+ use either the \c tr() function of an appropriate class, or the
+ QCoreApplication::translate() function directly:
\snippet snippets/code/doc_src_i18n.cpp 1
- Qt indexes each translatable string by the \e{translation context} it is
- associated with; this is generally the name of the QObject subclass it is
- used in.
+ \note If you disable the \c{const char *} to QString automatic conversion by
+ compiling your application with the macro \c QT_NO_CAST_FROM_ASCII defined,
+ you will most likely catch any strings you are missing. See
+ QString::fromUtf8() and QString::fromLatin1() for more information.
- Translation contexts are defined for new QObject-based classes by the use
- of the Q_OBJECT macro in each new class definition.
+ \section1 Use Parameters Instead of Concatenating Strings
- When tr() is called, it looks up the translatable string using a QTranslator
- object. For translation to work, one or more of these must have been
- installed on the application object in the way described in
- \l{Enabling Translation}.
+ Different languages arrange words differently in phrases, clauses, and
+ sentences, so do not create strings by concatenating words and data. Instead,
+ use \c % to insert parameters into strings.
- Translating strings in QML works exactly the same way as in C++, with the only
- difference being that you need to call qsTr() instead of \l{QObject::}{tr()}. See also
- the page on \l{Internationalization and Localization with Qt Quick}.
+ For example, in the string \c {After processing file %1, file %2 is next in
+ line}, \c{%1} and \c{%2} are numbered parameters. At runtime, \c{%1} and
+ \c{%2} are replaced with the first and second file names, respectively. The
+ same numbered parameters must appear in the translation, but not necessarily
+ in the same order. A German translation of the string might reverse the
+ phrases. For example, \c{Datei %2 wird bearbeitet, wenn Datei %1 fertig ist}.
+ Both numbered parameters appear in the translation, but in the reverse order.
- \section1 Defining a Translation Context
+ \section2 QML: Use .arg()
- The translation context for QObject and each QObject subclass is the
- class name itself. Developers subclassing QObject must use the
- Q_OBJECT macro in their class definition to override the translation
- context. This macro sets the context to the name of the subclass.
+ The following QML snippet has a string with two number parameters
+ \c %1 and \c %2. These parameters are inserted with the \c .arg() functions.
- For example, the following class definition includes the Q_OBJECT macro,
- implementing a new tr() that uses the \c MainWindow context:
+ \code
+ Text {
+ text: qsTr("File %1 of %2").arg(counter).arg(total)
+ }
+ \endcode
+
+ \c %1 refers to the first parameter and \c %2 refers to the second parameter,
+ so this code produces output like: \e {File 2 of 3}.
+
+ \section2 C++: Use QString::arg()
+
+ In C++, use the QString::arg() functions to substitute parameters:
+
+ \snippet snippets/code/doc_src_i18n.cpp 4
+
+ This code produces output like: \e {5 of 10 files copied. Copying:
+ somefile.txt}.
+
+ \section1 Handle Plural Forms
+
+ You can pass an additional integer parameter (\e n) to the translation
+ functions and use a special notation for plural forms (\c %n) in each
+ translatable string.
+
+ Depending on the value of \e n, the translation function returns a different
+ translation, with the correct grammatical number for the target language.
+ Also, any occurrence of \c %n is replaced with \e n's value.
+
+ For example, the English and French translations of the string
+ \c {%n message(s) saved} require different plural forms.
+
+ \table
+ \header
+ \li \e n
+ \li No Translation
+ \li French
+ \li English
+ \row
+ \li 0
+ \li "0 message(s) saved"
+ \li "0 message sauvegard\unicode{0xE9}"
+ \li "0 message\b{s} saved"
+ \row
+ \li 1
+ \li "1 message(s) saved"
+ \li "1 message sauvegard\unicode{0xE9}"
+ \li "1 message saved"
+ \row
+ \li 2
+ \li "2 message(s) saved"
+ \li "2 message\b{s} sauvegard\unicode{0xE9}\b{s}"
+ \li "2 message\b{s} saved"
+ \row
+ \li 37
+ \li "37 message(s) saved"
+ \li "37 message\b{s} sauvegard\unicode{0xE9}\b{s}"
+ \li "37 message\b{s} saved"
+ \endtable
+
+ This idiom also works with target languages that have several plural forms,
+ such as a \e dual form. In addition, the idiom handles the \e n \c {== 0}
+ case correctly for languages such as French that require the singular.
+
+ For a summary of the rules that \QL and \c lrelease use to translate strings
+ that contain plural forms, see \l{Translation Rules for Plural Forms}.
+
+ To handle plural forms in the native language, load a TS file for this
+ language, too. Use the \c lupdate tool \c -pluralonly command line option,
+ to create TS files that contain only entries with plural forms.
+
+ \section2 QML Example
+
+ The following QML code snippet replaces \c %n with the value of \c total:
\code
- class MainWindow : public QMainWindow
- {
- Q_OBJECT
+ Text {
+ text: qsTr("%n message(s) saved").arg(total)
+ }
+ \endcode
- public:
- MainWindow();
+ \section2 C++ Example
+
+ The following C++ code snippet replaces \c %n with the value that the
+ \c {count()} function returns:
+
+ \snippet snippets/code/src_corelib_kernel_qobject.cpp 18
+
+ \section1 Use Regional Number Settings
+
+ If you include the \c %L modifier when you specify a parameter, the number is
+ localized according to the current regional settings. The conversion uses the
+ default locale if you set it or the system-wide locale, otherwise.
+
+ \section2 QML: Use %L
+
+ For example, in the following QML snippet, \c %L1 formats the first
+ parameter according to the number formatting conventions of the currently
+ selected locale (geographical region):
+
+ \code
+ Text {
+ text: qsTr("%L1").arg(total)
+ }
\endcode
- \dots
- If Q_OBJECT is not used in a class definition, the context will be
- inherited from the base class. For example, since all QObject-based
- classes in Qt provide a context, a new QWidget subclass defined without
- a Q_OBJECT macro will use the \c QWidget context if its tr() function
- is invoked.
+ If \c total is the number \e {4321.56}, with English regional settings
+ (locale) the output is \e {4,321.56}, whereas with German regional settings
+ it is \e {4.321,56}.
+
+ \section2 C++: Use %Ln
+
+ In C++, you can use \c %Ln to produce a localized representation of \c n.
+ Use QLocale::setDefault() to set the default locale.
+
+ \keyword localization
+ \section1 Internationalize Date, Time, and Currency
+
+ Present date, time, and currency using the locally preferred formats.
- \section1 Using tr() to Obtain a Translation
+ \section2 QML: Use QtQml Functions
- The following example shows how a translation is obtained for the
- class shown in the previous section:
+ QML does not have special in-string modifiers for formatting dates and times.
+ Instead, you need to query the current locale (geographical region) and use
+ the methods of \l {QtQml::}{Date} to format the string.
+
+ \c Qt.locale() returns a \l {QtQml::}{Locale} object which contains
+ information about the locale. In particular, the \l {QtQml::Locale::name}
+ {Locale.name} property contains the language and country of the current
+ locale. You can use the value as is or parse it to determine the appropriate
+ content for the current locale.
+
+ The following snippet gets the current date and time with \c Date(), then
+ converts that to a string for the current locale. Then it inserts the date
+ string into the \c %1 parameter for the appropriate translation.
\code
- void MainWindow::createMenus()
- {
- fileMenu = menuBar()->addMenu(tr("&File"));
+ Text {
+ text: qsTr("Date %1").arg(Date().toLocaleString(Qt.locale()))
+ }
\endcode
- \dots
- Here, the translation context is \c MainWindow because it is the
- \c MainWindow::tr() function that is invoked. The text returned
- by the tr() function is a translation of "&File" obtained from
- the \c MainWindow context.
+ To localize currency numbers, use the \l {QtQml::}{Number} type. It has
+ similar functions as the \c Date type for converting numbers into localized
+ currency strings.
- When Qt's translation tool, \l{Using lupdate}{lupdate}, is used to process
- a set of source
- files, the text wrapped in tr() calls is stored in a section of the translation
- file that corresponds to its translation context.
+ \section2 C++: Use QLocale Class
- In some situations, it is useful to give a translation context explicitly
- by fully qualifying the call to tr(); for example:
+ In C++, use QLocale::timeFormat() or QLocale::toString(QTime) or
+ \c toString(QDate):
- \snippet snippets/code/src_corelib_kernel_qobject.cpp explicit tr context
+ \code
+ QLabel *label = new QLabel(this);
+ label->setText(tr("Date %1").arg(QLocale().toString(QDate::currentDate()));
+ \endcode
- This call obtains the translated text for "Page up" from the \c QScrollBar
- context. Developers can also use the QCoreApplication::translate() function
- to obtain a translation for a particular translation context.
+ \section1 Mark Translatable Data Text Strings
- \section1 Using tr() to Localize Numbers
+ Use \c _NoOp functions (in QML) and \c _NOOP macros (in C++) to mark
+ translatable string literals for extraction by the \c lupdate tool.
- You can localize numbers by using appropriate tr() strings:
+ \section2 QML: Use _NoOp Functions
- \snippet snippets/code/doc_src_i18n.cpp 11
+ In QML, use the following functions to mark translatable string literals:
- In the example, for the US we would leave the translation of
- "AMPM" as it is and thereby use the 12-hour clock branch; but in
- Europe we would translate it as something else to make
- the code use the 24-hour clock branch.
+ \list
+ \li \l [QML] {Qt::}{qsTrNoOp()}
+ \li \l [QML] {Qt::}{qsTranslateNoOp()}
+ \li \l [QML] {Qt::}{qsTrIdNoOp()}
+ \endlist
- \section1 Translating Non-Qt Classes
+ If the user changes the system language without a reboot, depending on the
+ system, the strings in arrays and list models and other data structures might
+ not be refreshed automatically. To force the texts to be refreshed when they
+ are displayed in the UI, you need to declare the strings with the
+ \c {qsTrNoOp()} function. Then, when you populate the objects for display,
+ you need to explicitly retrieve the translation for each text.
- It is sometimes necessary to provide internationalization support for
- strings used in classes that do not inherit QObject or use the Q_OBJECT
- macro to enable translation features. Since Qt translates strings at
- run-time based on the class they are associated with and \c lupdate
- looks for translatable strings in the source code, non-Qt classes must
- use mechanisms that also provide this information.
+ For example:
- One way to do this is to add translation support to a non-Qt class
- using the Q_DECLARE_TR_FUNCTIONS() macro; for example:
+ \code
+ ListModel {
+ id: myListModel
- \snippet snippets/i18n-non-qt-class/myclass.h 0
- \dots
- \snippet snippets/i18n-non-qt-class/myclass.h 1
+ ListElement {
+ //: Capital city of Finland
+ name: qsTrNoOp("Helsinki")
+ }
+ }
+
+ ...
- This provides the class with \l{QObject::}{tr()} functions that can
- be used to translate strings associated with the class, and makes it
- possible for \c lupdate to find translatable strings in the source
- code.
+ Text {
+ text: qsTr(myListModel.get(0).name)
+ // Get the translation of the name property in element 0
+ }
+ \endcode
- Alternatively, the QCoreApplication::translate() function can be called
- with a specific context, and this will be recognized by \c lupdate and
- Qt Linguist.
+ \section2 C++: Use _NOOP Macros
- \section1 Translator Comments
+ For translatable text completely outside a function, use the \l QT_TR_NOOP()
+ and \l QT_TRANSLATE_NOOP() macros that expand to just the text without the
+ context.
- Developers can include information about each translatable string to
- help translators with the translation process. These are extracted
- when \c lupdate is used to process the source files. The recommended
- way to add comments is to annotate the tr() calls in your code with
- comments of the form:
+ An example of \c QT_TR_NOOP():
- \tt{//: ...}
+ \snippet snippets/code/doc_src_i18n.cpp 2
- or
+ An example of \c QT_TRANSLATE_NOOP():
- \tt{\begincomment: ... \endcomment}
+ \snippet snippets/code/doc_src_i18n.cpp 3
- Examples:
+ \section1 Add Comments for Translators
- \snippet snippets/code/src_corelib_kernel_qobject.cpp 40
+ You can add comments in the source code before a string you mark as
+ translatable to clarify its purpose. The comments are included in the
+ TS files that you deliver to the translator.
- In these examples, the comments will be associated with the strings
- passed to tr() in the context of each call.
+ \note The TS files are XML files with the source texts and a place for the
+ translated text. The updated TS files are converted into binary translation
+ files and included as part of the final application.
- \section1 Adding Meta-Data to Strings
+ \section2 QML: Use //: and //~
- Additional data can be attached to each translatable message. These are
- extracted when \c lupdate is used to process the source files. The
- recommended way to add meta-data is to annotate the tr() calls in your code
- with comments of the form:
+ In the following code snippet, the text on the \c {//:} line is the main comment
+ for the translator.
- \tt{//= <id>}
+ The text on the \c{//~} line is optional extra information. The first word of
+ the text is used as an additional identifier in the XML element in the TS file
+ so make sure the first word is not part of the sentence. For example, the
+ comment \e {Context Not related to back-stepping} is converted to
+ \c {<extra-Context>Not related to back-stepping} in the TS file.
- This can be used to give the message a unique identifier to support tools
- which need it.
+ \code
+ Text {
+ id: txt1;
+ // This UI string is only used here
+ //: The back of the object, not the front
+ //~ Context Not related to back-stepping
+ text: qsTr("Back");
+ }
+ \endcode
+
+ \section2 C++: Use Comment Characters
- An alternative way to attach meta-data is to use the following syntax:
+ To add comments in C++, annotate the \c tr() calls in your code with
+ comments of the form \c {//:} or by marking the beginning and end of
+ the comment.
- \tt{//~ <field name> <field contents>}
+ In the following examples, the comments are associated with the strings
+ passed to \c tr() in the context of each call:
+
+ \snippet snippets/code/src_corelib_kernel_qobject.cpp 40
+
+ To add optional comments, use:
+
+ \code
+ //~ <field name> <field contents>
+ \endcode
- This can be used to attach meta-data to the message. The field name should
- consist of a domain prefix (possibly the conventional file extension of the
- file format the field is inspired by), a hyphen and the actual field name
- in underscore-delimited notation. For storage in TS files, the field name
- together with the prefix "extra-" will form an XML element name. The field
- contents will be XML-escaped, but otherwise appear verbatim as the
- element's contents. Any number of unique fields can be added to each
- message.
+ The field name should consist of a domain prefix (possibly the conventional
+ file extension of the file format the field is inspired by), a hyphen, and
+ the actual field name in underscore-delimited notation. For storage in TS
+ files, the field name together with the prefix \c extra- will form an XML
+ element name. The field contents will be XML-escaped, but otherwise appear
+ verbatim as the element's contents. You can add any number of unique fields
+ to each message.
Example:
\snippet snippets/code/src_corelib_kernel_qobject.cpp meta data
+ In C++, you use an equals sign to add a unique identifier:
+
+ \code
+ //= <id>
+ \endcode
+
You can use the keyword \e TRANSLATOR for translator comments.
- Meta-data appearing right in front of the TRANSLATOR keyword applies to
+ Metadata appearing right in front of the TRANSLATOR keyword applies to
the whole TS file.
- \section1 Disambiguation
+ \section1 Disambiguate Identical Text
- If the same translatable string is used in different roles within the same
- translation context, an additional identifying string may be passed in
- the call to \l{QObject::}{tr()}. This optional disambiguation argument
- is used to distinguish between otherwise identical strings.
+ The translation system consolidates the UI text strings into unique items to
+ avoid having to translate the same text multiple times. However, a text
+ might look identical to another text but have a different meaning. For
+ example, in English, \e back means both a step backward and the part of an
+ object opposite to the front. You need to tell the translation system about
+ these two separate meanings, so the translator can create two separate
+ translations.
- Example:
+ \section2 QML: Add a Disambiguator to qsTr()
+
+ In QML, add a disambiguating string as the second parameter of the \c qsTr()
+ function.
+
+ In the following code snippet, the ID \c {not front} differentiates this
+ \e Back text from the backstepping \e Back text:
+
+ \code
+ Text {
+ id: txt1
+ // This UI string is used only here
+ //: The back of the object, not the front
+ //~ Context Not related to back-stepping
+ text: qsTr("Back", "not front")
+ }
+ \endcode
+
+ \section2 C++: Add a Disambiguator to tr()
+
+ In C++, pass a disambiguating string in the call to \l{QObject::}{tr()}.
+
+ In the following code snippet, the ID \c recipient differentiates the name of
+ the recipient from that of the sender:
\snippet snippets/code/src_corelib_kernel_qobject.cpp 17
\dots
- In Qt 4.4 and earlier, this disambiguation parameter was the preferred
- way to specify comments to translators.
+ \section1 Make Keyboard Shortcuts Translatable
- \section1 Handling Plurals
+ In its most common form, a keyboard shortcut describes a combination of keys
+ that you press to perform some action. For \l{Standard Shortcuts}
+ {standard shortcuts}, use a standard key to request the platform-specific
+ key sequence associated with each shortcut.
- Some translatable strings contain placeholders for integer values and need
- to be translated differently depending on the values in use.
+ For custom shortcuts, use human-readable strings, such as \key Ctrl+Q or
+ \key Alt+F. You can translate them into the appropriate shortcuts for the
+ speakers of different languages.
- To help with this problem, developers pass an additional integer argument
- to the \l{QObject::}{tr()} function, and typically use a special notation
- for plurals in each translatable string.
+ If you hard-code keyboard shortcuts in your application, translators cannot
+ override them.
- If this argument is equal or greater than zero, all occurrences of
- \c %n in the resulting string are replaced with a decimal representation
- of the value supplied. In addition, the translation used will adapt to the
- value according to the rules for each language.
+ When you use keyboard shortcuts in menu item and button text, a
+ \e mnemonic character (marked by underlining) indicates that pressing
+ \key Alt or \key Ctrl with the underlined character performs the same action
+ as clicking the menu item or pressing the button.
- Example:
+ For example, applications often use \e F as the mnemonic character in the
+ \uicontrol {File} menu, so you can either click the menu item or press
+ \key {Alt+F} to open the menu. To define the mnemonic character in the
+ translatable string ("File"), prefix it with an ampersand: \c {"&File"}.
+ The translation for the string should also have an ampersand in it,
+ preferably in front of the same character.
- \snippet snippets/code/src_corelib_kernel_qobject.cpp 18
+ \section2 QML Example
- The table below shows what string is returned depending on the
- active translation:
+ In QML:
- \table
- \header \li \li{3,1} Active Translation
- \header \li \a n \li No Translation \li French \li English
- \row \li 0 \li "0 message(s) saved" \li "0 message sauvegard\unicode{0xE9}" \li "0 message\b{s} saved"
- \row \li 1 \li "1 message(s) saved" \li "1 message sauvegard\unicode{0xE9}" \li "1 message saved"
- \row \li 2 \li "2 message(s) saved" \li "2 message\b{s} sauvegard\unicode{0xE9}\b{s}" \li "2 message\b{s} saved"
- \row \li 37 \li "37 message(s) saved" \li "37 message\b{s} sauvegard\unicode{0xE9}\b{s}" \li "37 message\b{s} saved"
- \endtable
+ \badcode
+ Menu {
+ id: fileMenu
+ title: qsTr("&File")
- This idiom is more flexible than the traditional approach; e.g.,
+ MenuItem {
+ objectName: "quitMenuItem"
+ text: qsTr("E&xit")
+ onTriggered: Qt.quit()
+ }
+ }
+ \endcode
- \snippet snippets/code/src_corelib_kernel_qobject.cpp 19
+ \section2 C++: Use the QKeySequence Class
- because it also works with target languages that have several
- plural forms (e.g., Irish has a special "dual" form that should
- be used when \c n is 2), and it handles the \e n == 0 case
- correctly for languages such as French that require the singular.
+ In C++, use QAction and QKeySequence objects to specify the keyboard
+ shortcuts that trigger actions:
- To handle plural forms in the native language, you need to load a
- translation file for this language, too. The lupdate tool has the
- \c -pluralonly command line option, which allows the creation of
- TS files containing only entries with plural forms.
+ \code
+ exitAct = new QAction(tr("E&xit"), this);
+ exitAct->setShortcuts(QKeySequence::Quit);
+ \endcode
- See the \l{Qt Quarterly} Article
- \l{http://doc.qt.io/archives/qq/qq19-plurals.html}
- {Plural Forms in Translations} for further details on this issue.
+ The translations of keyboard shortcuts are associated with the QShortcut
+ context.
- Instead of \c %n, you can use \c %Ln to produce a localized
- representation of \a n. The conversion uses the default locale,
- set using QLocale::setDefault(). (If no default locale was
- specified, the system wide locale is used.)
+ \section1 Use Locale to Extend Localization Features
- A summary of the rules used to translate strings containing plurals can be
- found in the \l{Translation Rules for Plurals} document.
+ You might find different graphics or audio more suitable for different
+ geographical regions.
- \section1 Translating Text That is Outside of a QObject Subclass
+ Generally, try to avoid localizing images. Create icons that are globally
+ appropriate, rather than relying on local puns or stretched metaphors.
+ However, you might have to reverse images of left and right pointing arrows
+ for Arabic and Hebrew locales.
- \section2 Using QCoreApplication::translate()
+ Locale is one of the default file selectors, so you can use file selection
+ to display different images that you deliver as resources depending on the
+ system locale.
- If the quoted text is not in a member function of a QObject subclass,
- use either the tr() function of an appropriate class, or the
- QCoreApplication::translate() function directly:
+ The QML and C++ code examples in the following sections assume that you
+ deliver the following files in the application resources and use language
+ and country codes as the subfolder names:
- \snippet snippets/code/doc_src_i18n.cpp 13
+ \badcode
+ images
+ ├── language-icon.png
+ ├── +en_GB
+ │ └── language-icon.png
+ └── +fi_FI
+ └── language-icon.png
+ \endcode
- \section2 Using QT_TR_NOOP() and QT_TRANSLATE_NOOP() in C++
+ \section2 QML: Set Image Source
- If you need to have translatable text completely outside a function, there
- are two macros to help: QT_TR_NOOP() and QT_TRANSLATE_NOOP(). They merely
- mark the text for extraction by the \c lupdate tool. The macros expand to
- just the text (without the context).
+ The following QML code snippet shows how to select an icon source image
+ according to the current locale:
- Example of QT_TR_NOOP():
+ \code
+ icon.source: "qrc:/images/language-icon.png"
+ \endcode
- \snippet snippets/code/doc_src_i18n.cpp 2
+ \section2 C++: Use QFileSelector
- Example of QT_TRANSLATE_NOOP():
+ The following C++ code snippet uses QFileSelector to pick a language icon
+ from the \c images folder according to the system locale:
- \snippet snippets/code/doc_src_i18n.cpp 3
+ \code
+ const QFileSelector selector;
+ const QIcon languageIcon(selector.select(":/images/language-icon.png"));
+ \endcode
+
+ \section1 Enable Translation
+
+ TS file names must contain ISO language and country codes:
+
+ \list
+ \li \e language is an \l {https://www.iso.org/iso-639-language-codes.html}
+ {ISO-639} language code in lowercase.
+ \li \e country is an \l {https://www.iso.org/iso-3166-country-codes.html}
+ {ISO-3166} two-letter country code in uppercase.
+ \endlist
+
+ For example, \c qml_de.ts sets the target language to German, and
+ \c qml_de_CH.ts sets the target language to German and the target
+ country to Switzerland. The \c lrelease tool generates QM files
+ called \c qml_de.qm and \c qml_de_CH.qm that the application loads
+ depending on the system locale.
+
+ \section2 QML: Use QQmlApplicationEngine
+
+ In QML, use \l QQmlApplicationEngine to automatically load translation files
+ from a subdirectory called \c i18n in the directory that contains the main
+ QML file. The translation file names must have the prefix \c qml_.
+ For example, \c qml_en_US.qm.
+
+ Applications reload translations when the \l QJSEngine::uiLanguage or
+ \l {Qt::uiLanguage}{Qt.uiLanguage} property value changes.
+
+ \section2 C++: Use QTranslator
- If you disable the \c{const char *} to QString automatic
- conversion by compiling your software with the macro \c
- QT_NO_CAST_FROM_ASCII defined, you'll be very likely to catch any
- strings you are missing. See QString::fromUtf8() and QString::fromLatin1()
- for more information.
+ In C++, the TS file names must contain the application name. For example,
+ \c app_de_DE.ts.
- \section1 Using QKeySequence() for Accelerator Values
+ Typically, your Qt C++ application's \c main() function will look like
+ this:
+
+ \snippet snippets/code/doc_src_i18n.cpp 8
+
+ For a translation-aware application, you create a QTranslator object,
+ \l {QTranslator::load()}{load} a translation according to the user's
+ UI display locale at runtime, and install the translator object into
+ the application.
+
+ \section1 Additional Considerations for C++ Code
+
+ The following sections contain more information about using the Qt C++
+ classes and functions in translatable applications:
+
+ \list
+ \li \l {Use QString for All User-Visible Text}
+ \li \l {Define a Translation Context}
+ \li \l {Translate Non-Qt Classes}
+ \li \l {Translate Text That is Outside of a QObject Subclass}
+ \li \l {Prepare for Dynamic Language Changes}
+ \endlist
- Accelerator values such as Ctrl+Q or Alt+F need to be translated
- too. If you hard-code \c{Qt::CTRL + Qt::Key_Q} for "quit" in your
- application, translators won't be able to override it. The
- correct idiom is:
+ \section2 Use QString for All User-Visible Text
+
+ QString uses the \l {Unicode in Qt}{Unicode} encoding internally, and
+ therefore you can use familiar text processing operations to transparently
+ process all languages in the world. Also, since all Qt functions
+ that present text to the user take a QString object as a parameter,
+ there is no \c{char *} to QString conversion overhead.
+
+ \section2 Define a Translation Context
+
+ The translation context for QObject and each QObject subclass is the
+ class name itself. If you subclass QObject, use the Q_OBJECT macro in the
+ class definition to override the translation context. The macro sets the
+ context to the name of the subclass.
+
+ For example, the following class definition includes the Q_OBJECT macro,
+ implementing a new \c tr() function that uses the \c MainWindow context:
\code
- exitAct = new QAction(tr("E&xit"), this);
- exitAct->setShortcuts(QKeySequence::Quit);
+ class MainWindow : public QMainWindow
+ {
+ Q_OBJECT
+
+ public:
+ MainWindow();
\endcode
+ \dots
- \section1 Using Numbered Arguments
+ If you do not use Q_OBJECT in a class definition, the context is
+ inherited from the base class. For example, since all QObject-based
+ classes in Qt provide a context, a new QWidget subclass defined without
+ a Q_OBJECT macro uses the \c QWidget context if you invoke its \c tr()
+ function.
- The QString::arg() functions offer a simple means for substituting
- arguments:
- \snippet snippets/code/doc_src_i18n.cpp 4
+ \section2 Translate Non-Qt Classes
- In some languages the order of arguments may need to change, and this
- can easily be achieved by changing the order of the % arguments. For
- example:
+ You must provide extra information for \c lupdate about strings in classes
+ that do not inherit QObject or use the Q_OBJECT macro. To add translation
+ support to a non-Qt class, you can use the Q_DECLARE_TR_FUNCTIONS() macro.
+ For example:
+
+ \snippet snippets/i18n-non-qt-class/myclass.h 0
+ \dots
+ \snippet snippets/i18n-non-qt-class/myclass.h 1
- \snippet snippets/code/doc_src_i18n.cpp 5
+ This provides the class with \l{QObject::}{tr()} functions that you can use
+ to translate strings associated with the class, and enables \c lupdate to
+ find translatable strings in the source code.
- produces the correct output in English and Norwegian:
- \snippet snippets/code/doc_src_i18n.qdoc 6
+ Alternatively, you can call the QCoreApplication::translate() function
+ with a specific context that \c lupdate and Qt Linguist recognize.
- \section1 Further Reading
+ \section2 Translate Text That is Outside of a QObject Subclass
- \l{Qt Linguist Manual}, \l{Hello tr() Example}, \l{Translation Rules for Plurals}
+ If the quoted text is not in a member function of a QObject subclass,
+ use either the \c tr() function of an appropriate class or the
+ QCoreApplication::translate() function directly:
+
+ \snippet snippets/code/doc_src_i18n.cpp 13
+
+ \section2 Prepare for Dynamic Language Changes
+
+ To make Qt widgets aware of changes to the installed QTranslator objects,
+ reimplement the widget's \l{QWidget::changeEvent()}{changeEvent()} function
+ to check whether the event is a \l{QEvent::LanguageChange}{LanguageChange}
+ event and update the text displayed by widgets using the \l{QObject::tr()}
+ {tr()} function in the usual way. For example:
+
+ \snippet snippets/code/doc_src_i18n.cpp 12
+
+ All other change events should be passed on by calling the default
+ implementation of the function.
+
+ The list of installed translators might change in response to a
+ \l{QEvent::LocaleChange}{LocaleChange} event, or the application might
+ provide a UI that allows the user to change the current
+ application language.
+
+ The default event handler for QWidget subclasses responds to the
+ QEvent::LanguageChange event, and calls the \c {changeEvent()}
+ function when necessary.
+
+ \l{QEvent::LanguageChange}{LanguageChange} events are posted when you use
+ the QCoreApplication::installTranslator() function to install a new
+ translation. Other application components can also force widgets to update
+ themselves by posting \c LanguageChange events to them.
*/
/*!
\page i18n-plural-rules.html
- \title Translation Rules for Plurals
+ \title Translation Rules for Plural Forms
\ingroup internationalization
- \previouspage Writing Source Code for Translation
- \brief A summary of the translation rules for plurals produced by Qt's i18n tools.
+ \previouspage Localizing Applications
+ \brief A summary of the translation rules for plural forms produced by Qt's
+ translation tools.
- The table below shows the specific rules that are produced by Qt Linguist
- and \c lrelease for a selection of languages. Cells marked \e otherwise
- indicate the form used when none of the other rules are appropriate for a
+ The table below shows the specific rules that Qt Linguist and \c lrelease
+ follow for a selection of languages. Cells marked \e otherwise indicate the
+ form the tools use when none of the other rules are appropriate for a
specific language.
\table 80%
@@ -814,6 +968,4 @@
\li \e{otherwise}
\row \li Japanese \li \e{otherwise} \li N/A \li N/A
\endtable
-
- The rules themselves are not documented and are internal to Qt Linguist and \c lrelease.
*/
diff --git a/doc/src/internationalization/l10n.qdoc b/doc/src/internationalization/l10n.qdoc
new file mode 100644
index 00000000..85c9c92c
--- /dev/null
+++ b/doc/src/internationalization/l10n.qdoc
@@ -0,0 +1,248 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page localization.html
+ \previouspage Writing Source Code for Translation
+ \nextpage Translation Rules for Plural Forms
+
+ \ingroup internationalization
+
+ \title Localizing Applications
+ \brief Localizing Qt and Qt Quick apps into multiple languages.
+
+ The steps to localize applications include creating translatable
+ applications, preparing them for translation, translating the
+ strings, and creating runtime translation files for the released
+ application.
+
+ Qt Quick and Qt C++ applications use the same underlying localization system:
+ \c lupdate, \c lrelease, and the translation source (TS) files and QM files
+ that they generate. You use the same tools for both QML and C++ code, as
+ described in the \l {Qt Linguist Manual}.
+
+ You can even have user interface strings in QML and C++ source files in the
+ same application. The system will create a single combined translation file
+ and the strings are accessible from QML and C++ code.
+
+ To localize internationalized applications:
+
+ \list
+ \li \l {Specify Translation Sources in Qt Project Files}
+ \li \l {Deploy Translations}
+ \li \l {Use Qt Module Translations}
+ \endlist
+
+ \section1 Specify Translation Sources in Qt Project Files
+
+ To enable \c lupdate and \c lrelease to generate TS and QM files, update the
+ application project file to specify the source files that contain text
+ to be translated.
+
+ Use ISO language and country codes in the TS file name to determine
+ the language to load at runtime. For more information, see \l Languages.
+
+ The \c lupdate tool extracts user interface strings from your application.
+ It expects all source code to be encoded in UTF-8 by default. For more
+ information, see \l{Encoding}.
+
+ \section2 Using CMake
+
+ With \c CMake's target based API, the QML sources are passed
+ \c{qt_add_qml_module}'s \c QML_FILES property. The \c{qt_add_lupdate} function
+ collects them from the target.
+
+ Add the \l{cmake-commands-qtlinguisttools}{CMake commands} to
+ the \c CMakeLists.txt file. The following example adds translations
+ for an \e Arrowpad application:
+
+ \badcode
+ find_package(Qt6 REQUIRED COMPONENTS LinguistTools)
+
+ ...
+
+ qt6_add_translations(arrowpad
+ TS_FILES arrowpad_fr.ts arrowpad_nl.ts
+ QM_FILES_OUTPUT_VARIABLE qm_files)
+ install(FILES ${qm_files} DESTINATION ${INSTALL_EXAMPLEDIR})
+ \endcode
+
+ \section2 Using qmake
+
+ When using qmake, set a conditional statement to hide the QML source from the
+ compiler that you list in the \c SOURCES or \c HEADERS entry in the .pro file.
+
+ The SOURCES variable is intended for C++ source files. If you list QML
+ or JavaScript source files there, the compiler tries to build them as though
+ they are C++ files. As a workaround, you can use an \c lupdate_only{...}
+ conditional statement so the \c lupdate tool sees the .qml files but the C++
+ compiler ignores them.
+
+ For example, the following .pro file snippet specifies two .qml files in
+ the application.
+
+ \code
+ lupdate_only{
+ SOURCES = main.qml \
+ MainPage.qml
+ }
+ \endcode
+
+ You can also specify the .qml source files with a wildcard match. The
+ search is not recursive, so you need to specify each directory that
+ contains source files that contain UI strings:
+
+ \code
+ lupdate_only{
+ SOURCES = *.qml \
+ *.js \
+ content/*.qml \
+ content/*.js
+ }
+ \endcode
+
+ \section1 Deploy Translations
+
+ Place the \c .qm files required for the application in a location where the
+ loader code using \l QTranslator can find them. Typically, you specify a path
+ relative to \l QCoreApplication::applicationDirPath().
+
+ In addition to the application's QM files, you need to deploy the QM files
+ for the Qt modules that you use in the application, unless they are installed
+ on the system.
+
+ The QM files are split up by module and there is a so-called meta catalog
+ file which includes the QM files of all modules. However, you only need to
+ deploy the QM files for the modules that you use in the application.
+
+ You can use the \c lconvert tool in the deploy step to concatenate the
+ required QM files into one file that matches the meta catalog file.
+ For example, to create a German translation file for an application that
+ uses the \l{Qt Core}, \l {Qt GUI}, and \l {Qt Quick} modules, run:
+
+ \code
+ lconvert -o installation_folder/qt_de.qm qtbase_de.qm qtdeclarative_de.qm
+ \endcode
+
+ \section1 Use Qt Module Translations
+
+ \target qt-itself
+ Qt modules contain several thousands of strings that also need to be
+ translated into the languages that you are targeting. You can find a
+ number of TS files in the \l {https://code.qt.io/cgit/qt/qttranslations.git/}
+ {qttranslations} repository. Before you start translating Qt, read the
+ wiki page \l{external: Translating Qt Into Other Languages}
+ {Translating Qt Into Other Languages}.
+
+ \section2 Locating Qt Translations
+
+ You can use QLibraryInfo::path() to locate the translations for the
+ Qt modules that your application uses. You can request the path to the
+ translations at run-time by passing QLibraryInfo::TranslationsPath to this
+ function.
+
+ \section2 Available Catalogs
+
+ The Qt translation catalogs are located in the \c qttranslations repository.
+
+ \warning Qt translations are contributed by the Qt community, and provided
+ without any guarantees. Translations might be missing, outdated, or entirely
+ incorrect, up to the point of being malicious. It is recommended that you
+ audit any translations you ship.
+
+ In Qt 4, there is one big, monolithic \c .qm file per locale. For example,
+ the file \c qt_de.qm contains the German translation of all libraries.
+
+ The \c qt_ meta catalog contains the still-existing Qt translations that
+ were included in the \c qt_ catalog in Qt 4. It was created to make porting
+ applications from Qt 4 to Qt 5 easier. The meta catalog depends on
+ translations that might be absent, because they belong to unnecessary or
+ deprecated modules, which might cause the loading of the translations to
+ fail. If you use modules that are new in Qt 5 or later in your application,
+ you must specify the names of the catalogs for those modules even if you
+ use the meta catalog.
+
+ The following table lists the translation catalogs available for the Qt
+ modules and tools in Qt.
+
+ \table
+ \header
+ \li Qt Module or Tool
+ \li Catalog
+ \row
+ \li \l {Qt Bluetooth}
+ \li \c qtconnectivity
+ \row
+ \li \l [QtConcurrent]{Qt Concurrent}
+ \li \c qtbase
+ \row
+ \li \l [QtCore]{Qt Core}
+ \li \c qtbase
+ \row
+ \li \l [QtDBus]{Qt D-Bus}
+ \li \c qtbase
+ \row
+ \li \l {Qt Designer}
+ \li \c designer
+ \row
+ \li \l [QtGui]{Qt GUI}
+ \li \c qtbase
+ \row
+ \li \l {Qt Help}
+ \li \c qt_help
+ \row
+ \li \l {Qt Linguist Manual}{Qt Linguist}
+ \li \c linguist
+ \row
+ \li \l {Qt Location}
+ \li \c qtlocation
+ \row
+ \li \l {Qt Multimedia}
+ \li \c qtmultimedia
+ \row
+ \li \l[Qt Network]{Qt Network}
+ \li \c qtbase
+ \row
+ \li \l {Qt NFC}
+ \li \c qtconnectivity
+ \row
+ \li \l [QtPrintSupport]{Qt Print Support}
+ \li \c qtbase
+ \row
+ \li \l {Qt QML}
+ \li \c qtdeclarative
+ \row
+ \li \l {Qt Quick}
+ \li \c qtdeclarative
+ \row
+ \li \l {Qt Quick Controls}
+ \li \c qtdeclarative
+ \row
+ \li \l {Qt Quick Widgets}
+ \li \c qtdeclarative
+ \row
+ \li \l {Qt Serial Port}
+ \li \c qtserialport
+ \row
+ \li \l [QtSql]{Qt SQL}
+ \li \c qtbase
+ \row
+ \li \l [QtWidgets]{Qt Widgets}
+ \li \c qtbase
+ \row
+ \li \l {Qt WebSockets}
+ \li \c qtsockets
+ \row
+ \li \l {Qt WebEngine}
+ \li \c qtwebengine
+ \endtable
+
+ \section2 Example: Essential Qt Modules
+
+ For example, to locate translations for essential Qt modules, such as Qt Core,
+ Qt GUI, Qt Network, and Qt Widgets, add the following code to the \c main()
+ function:
+
+ \snippet snippets/code/doc_src_i18n.cpp 14
+
+*/
diff --git a/doc/src/qmlapp/internationalization.qdoc b/doc/src/qmlapp/internationalization.qdoc
deleted file mode 100644
index df6a25d0..00000000
--- a/doc/src/qmlapp/internationalization.qdoc
+++ /dev/null
@@ -1,272 +0,0 @@
-// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
-
-/*!
-\page qtquick-internationalization.html
-\title Internationalization and Localization with Qt Quick
-\brief Following these steps, you can write your Qt Quick application so it can be localized for multiple languages
-
-\section1 Internationalizing Your Application
-
-The following sections describe various aspects of internationalizing your QML
-source code. If you follow these guides for all the user interface components in
-your application, it becomes possible to localize every aspect of your
-application for different languages and local cultural conventions such as the
-way dates and numbers are formatted.
-
-\section2 1. Use qsTr() for all Literal User Interface Strings
-
-Strings in QML can be marked for translation using the qsTr(), qsTranslate(),
-qsTrId(), QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and QT_TRID_NOOP() functions. The
-most common way of marking strings is with the qsTr() function. For example:
-
-\code
-Text {
- id: txt1;
- text: qsTr("Back");
-}
-\endcode
-
-This code makes "Back" a key entry in the translation files. At runtime, the
-translation system looks up the keyword "Back" and then gets the corresponding
-translation value for the current system locale. The result is returned to the
-\c text property and the user interface will show the appropriate translation of
-"Back" for the current locale.
-
-
-\section2 2. Add Context for the Translator
-
-User interface strings are often short so you need to help the person
-translating the text understand the context of the text. You can add context
-information in the source code as extra descriptive text before the string to be
-translated. These extra descriptions are included in the .ts translation files
-delivered to the translator.
-
-\note The .ts files are XML files with the source texts and a place for the
-translated text. The updated .ts files are converted into binary translation
-files and included as part of the final application.
-
-In the following code snippet, the text on the \c {//:} line is the main comment
-for the translator.
-
-The text on the \c{//~} line is optional extra information. The first word of
-the text is used as an additional identifier in the XML element in the .ts file
-so make sure the first word is not part of the sentence. For example, the
-comment "Context Not related to that" is converted to "<extra-Context>Not
-related to that" in the .ts file.
-
-\code
-Text {
- id: txt1;
- // This user interface string is only used here
- //: The back of the object, not the front
- //~ Context Not related to back-stepping
- text: qsTr("Back");
-}
-\endcode
-
-\section2 3. Disambiguate Identical Texts
-
-The translation system consolidates the user interface text strings into unique
-items. This consolidation saves the person doing the translation work having to
-translate the same text multiple times. However, in some cases, the text is
-identical but has a different meaning. For example, in English, "back" means
-take a step backward and also means the part of an object opposite to the front.
-You need to tell the translation system about these two separate meanings so the
-translator can create two separate translations.
-
-Differentiate between identical texts by adding some id text as the second
-parameter of the qsTr() function.
-
-In the following code snippet, the \c {not front} text is an id to differentiate
-this "Back" text from the backstepping "Back" text:
-
-\code
-Text {
- id: txt1;
- // This user interface string is used only here
- //: The back of the object, not the front
- //~ Context Not related to back-stepping
- text: qsTr("Back", "not front");
-}
-\endcode
-
-\section2 4. Use \c %x to Insert Parameters into a String
-
-Different languages put words together in different orders so it is not a good
-idea to create sentences by concatenating words and data. Instead, use \c % to
-insert parameters into strings. For example, the following snippet has a string
-with two number parameters \c %1 and \c %2. These parameters are inserted with
-the \c .arg() functions.
-
-\code
-Text {
- text: qsTr("File %1 of %2").arg(counter).arg(total)
-}
-\endcode
-
-%1 refers to the first parameter and \c %2 refers to the second parameter so this
-code produces output like: "File 2 of 3".
-
-\section2 5. Use %Lx so Numbers are Localized
-
-If you include the \c %L modifier when you specify a parameter, the number is
-localized according to the current regional settings. For example, in the
-following code snippet, \c %L1 means to format the first parameters according to
-the number formatting conventions of the currently selected locale (geographical
-region):
-
-\code
-Text {
- text: qsTr("%L1").arg(total)
-}
-\endcode
-
-Then, with the above code, if \c total is the number "4321.56" (four thousand
-three hundred and twenty one point fifty six); with English regional settings,
-(locale) the output is "4,321.56"; with German regional settings, the output is
-"4.321,56".
-
-\section2 6. Internationalize Dates, Times and Currencies
-
-There are no special in-string modifiers for formatting dates and times.
-Instead, you need to query the current locale (geographical region) and use the
-methods of \l {QtQml::}{Date} to format the string.
-
-\c Qt.locale() returns a \l {QtQml::}{Locale} object which contains all
-kinds of information about the locale. In particular, the \l
-{QtQml::Locale::name}{Locale.name} property contains the language and country
-information for the current locale. You can use the value as is, or you can
-parse it to determine the appropriate content for the current locale.
-
-The following snippet gets the current date and time with Date(), then converts
-that to a string for the current locale. Then it inserts the date string into
-the %1 parameter for the appropriate translation.
-
-\code
-Text {
- text: qsTr("Date %1").arg(Date().toLocaleString(Qt.locale()))
-}
-\endcode
-
-To make sure currency numbers are localized, use the \l
-{QtQml::}{Number} type. This type has similar functions as the Date
-type for converting numbers into localized currency strings.
-
-\section2 7. Use QT_TR_NOOP() for Translatable Data Text Strings
-
-If the user changes the system language without a reboot, depending on the
-system, the strings in arrays and list models and other data structures might
-not be refreshed automatically. To force the texts to be refreshed when they are
-displayed in the user interface, you need to declare the strings with the
-QT_TR_NOOP() macro. Then, when you populate the objects for display, you need to
-explicitly retrieve the translation for each text. For example:
-
-\code
-ListModel {
- id: myListModel;
- ListElement {
- //: Capital city of Finland
- name: QT_TR_NOOP("Helsinki");
- }
- }
-
-...
-
-Text {
- text: qsTr(myListModel.get(0).name); // get the translation of the name property in element 0
- }
-\endcode
-
-
-\section2 8. Use Locale to Extend Localization Features
-
-If you want different graphics or audio for different geographical regions, you
-can use Qt.locale() to get the current locale. Then you choose appropriate
-graphics or audio for that locale.
-
-The following code snippet shows how you could select an appropriate icon
-that represents the language of the current locale.
-
-\code
-Component.onCompleted: {
- switch (Qt.locale().name.substring(0,2)) {
- case "en": // show the English-language icon
- languageIcon = "../images/language-icon_en.png";
- break;
- case "fi": // show the Finnish language icon
- languageIcon = "../images/language-icon_fi.png";
- break;
- default: // show a default language icon
- languageIcon = "../images/language-icon_default.png";
- }
-}
-\endcode
-
-\section2 9. Prepare for Dynamic Language Changes
-
-You can change the language that Qt translation functions use by adding and
-removing translators with QCoreApplication::installTranslator() and
-QCoreApplication::removeTranslator(). Afterwards you can call
-QQmlEngine::retranslate() to trigger a refresh of all bindings that use
-translations. As a result, your user interface will switch, dynamically, to the
-newly selected language.
-
-Alternatively, you can also forward a QEvent::LanguageChange event to your
-application's QQmlEngine instance or connect your own signal to
-QQmlEngine::retranslate().
-
-\section1 Localizing Your Application
-
-Qt Quick applications use the same underlying localization system as Qt C++
-applications (lupdate, lrelease and .ts files). You use the same tools as
-described in the \l {Qt Linguist Manual: Release Manager}{Qt Linguist Manual}.
-You can even have user interface strings in C++ and QML source in the same
-application. The system will create a single combined translation file and the
-strings are accessible from QML and C++.
-
-\section2 Use a Conditional to Hide QML Source From the Compiler
-
-\note The following section only applies to \c qmake projects. With \c CMake's
-target based API, the QML sources are passed \c{qt_add_qml_module}'s QML_FILES
-property. \c{qt_add_lupdate} will then collect them from the target.
-
-The \c lupdate tool extracts user interface strings from your application.
-lupdate reads your application's .pro file to identify which source files
-contain texts to be translated. This means your source files must be listed in
-the \c SOURCES or \c HEADERS entry in the .pro file. If your files are not
-listed the texts in them will not be found.
-
-However, the SOURCES variable is intended for C++ source files. If you list QML
-or JavaScript source files there, the compiler tries to build them as though
-they are C++ files. As a workaround, you can use an \c lupdate_only{...}
-conditional statement so the \c lupdate tool sees the .qml files but the C++
-compiler ignores them.
-
-For example, the following .pro file snippet specifies two .qml files in
-the application.
-
-\code
-lupdate_only{
-SOURCES = main.qml \
- MainPage.qml
-}
-\endcode
-
-
-You can also specify the .qml source files with a wildcard match. The
-search is not recursive so you need to specify each directory where there are
-user interface strings in the source code:
-
-\code
-lupdate_only{
-SOURCES = *.qml \
- *.js \
- content/*.qml \
- content/*.js
-}
-\endcode
-
-See the \l {Qt Linguist Manual} for more details about Qt localization.
-
-*/
diff --git a/doc/src/qmlapp/usecases/text.qdoc b/doc/src/qmlapp/usecases/text.qdoc
index 8a982d5e..66aaae12 100644
--- a/doc/src/qmlapp/usecases/text.qdoc
+++ b/doc/src/qmlapp/usecases/text.qdoc
@@ -39,7 +39,7 @@ orientation and the language settings.
The following pages go into detail about these various topics.
\list
\li \l{Right-to-left User Interfaces}
-\li \l{Internationalization and Localization with Qt Quick}
+\li \l{Internationalization with Qt}
\li \l{Scalability}
\endlist
diff --git a/doc/src/snippets/code/doc_src_i18n.cpp b/doc/src/snippets/code/doc_src_i18n.cpp
index 3452d2d7..a258d475 100644
--- a/doc/src/snippets/code/doc_src_i18n.cpp
+++ b/doc/src/snippets/code/doc_src_i18n.cpp
@@ -70,15 +70,6 @@ void FileCopier::showProgress(int done, int total,
//! [4]
-//! [5]
-QString s1 = "%1 of %2 files copied. Copying: %3";
-QString s2 = "Kopierer nu %3. Av totalt %2 filer er %1 kopiert.";
-
-qDebug() << s1.arg(5).arg(10).arg("somefile.txt");
-qDebug() << s2.arg(5).arg(10).arg("somefile.txt");
-//! [5]
-
-
//! [8]
int main(int argc, char *argv[])
{
@@ -109,18 +100,6 @@ QString string = codec->toUnicode(encodedString);
//! [10]
-//! [11]
-void Clock::setTime(const QTime &time)
-{
- if (tr("AMPM") == "AMPM") {
- // 12-hour clock
- } else {
- // 24-hour clock
- }
-}
-//! [11]
-
-
//! [12]
void MyWidget::changeEvent(QEvent *event)
{
diff --git a/doc/src/snippets/code/doc_src_i18n.qdoc b/doc/src/snippets/code/doc_src_i18n.qdoc
index dbfca61c..a84076d4 100644
--- a/doc/src/snippets/code/doc_src_i18n.qdoc
+++ b/doc/src/snippets/code/doc_src_i18n.qdoc
@@ -1,12 +1,6 @@
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [6]
-5 of 10 files copied. Copying: somefile.txt
-Kopierer nu somefile.txt. Av totalt 10 filer er 5 kopiert.
-//! [6]
-
-
//! [7]
HEADERS = funnydialog.h \
wackywidget.h
diff --git a/doc/src/snippets/code/src_corelib_kernel_qobject.cpp b/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
index bf024c93..b4e17510 100644
--- a/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
+++ b/doc/src/snippets/code/src_corelib_kernel_qobject.cpp
@@ -207,11 +207,6 @@ showMessage(tr("%n message(s) saved", "", n));
//! [18]
-//! [19]
-n == 1 ? tr("%n message saved") : tr("%n messages saved")
-//! [19]
-
-
//! [20]
label->setText(tr("F\374r \310lise"));
//! [20]
@@ -458,7 +453,3 @@ if (isSignalConnected(QMetaMethod::fromSignal(&MyObject::valueChanged))) {
//~ magic-stuff This might mean something magic.
QString text = MyMagicClass::tr("Sim sala bim.");
//! [meta data]
-
-//! [explicit tr context]
-QString text = QScrollBar::tr("Page up");
-//! [explicit tr context]