Writing source code for translation
In this section, we will discuss how to mark strings as translatable strings and how to use the tools provided by Qt. Wherever your application uses a quoted string that is visible to the user, make sure the QCoreApplication::translate()
method processes it. To do this, simply use the tr()
method to mark the strings as translatable that are meant for display purposes. This feature is used to show which text strings are translatable inside your C++ source files.
For example, if you want to use a QLabel
to show text on a user interface, then embed the text inside the tr()
method as follows:
QLabel *label = new QLabel(tr("Welcome"));
The class name is the translation context for the QObject
and its derived classes. To override the context, QObject
-derived classes must use the Q_OBJECT
macro in their class definition. This macro sets the context for the derived classes.
Qt provides several convenience macros and methods for internationalization...