![]() Any number of unique fields can be added to each message. The field contents will be XML-escaped, but otherwise appear verbatim as the element's contents. For storage in TS files, the field name together with the prefix "extra-" will form an XML element name. 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. This can be used to attach meta-data to the message. This can be used to give the message a unique identifier to support tools which need it.Īn alternative way to attach meta-data is to use the following syntax: The recommended way to add meta-data is to annotate the tr() calls in your code with comments of the form: These are extracted when lupdate is used to process the source files. Adding Meta-Data to StringsĪdditional data can be attached to each translatable message. In these examples, the comments will be associated with the strings passed to tr() in the context of each call. *: This text refers to a C++ code example. This macro sets the context to the name of the subclass.įor example, the following class definition includes the Q_OBJECT macro, implementing a new tr() that uses the MainWindow context: Developers subclassing QObject must use the Q_OBJECT macro in their class definition to override the translation context. The translation context for QObject and each QObject subclass is the class name itself. See also the page on Internationalization and Localization with Qt Quick. 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 tr(). For translation to work, one or more of these must have been installed on the application object in the way described in Enabling Translation. ![]() When tr() is called, it looks up the translatable string using a QTranslator object. Translation contexts are defined for new QObject-based classes by the use of the Q_OBJECT macro in each new class definition. Qt indexes each translatable string by the translation context it is associated with this is generally the name of the QObject subclass it is used in. QCoreApplication ::translate( "LoginWidget", "Password:"), logwid) Void same_global_function(LoginWidget *logwid) LoginWidget ::tr( "Password:"), logwid) Void some_global_function(LoginWidget *logwid) This function is also used to indicate which text strings in an application are translatable.įor example, assuming the LoginWidget is a subclass of QWidget: Essentially all that is necessary to achieve this is to use the tr() function to obtain translated text for your classes, typically for display purposes. Wherever your program uses a string literal (quoted text) that will be presented to the user, ensure that it is processed by the QCoreApplication::translate() function. If your C string literal uses a different encoding, use QString::fromLatin1() or QTextCodec to convert the literal to a Unicode encoded QString. You're unlikely to notice that you are using Unicode QString, and QChar are just easier versions of the crude const char * and char from traditional C.Ĭhar * strings in source code are assumed to be UTF-8 encoded when being implicitly converted to a QString. Strings that are in "programmer space" (such as QObject names and file format texts) need not use QString the traditional char * or the QByteArray class will suffice. Also, since all Qt functions that present text to the user take a QString as a parameter, there is no char * to QString conversion overhead. Since QString uses the Unicode encoding internally, every language in the world can be processed transparently using familiar text processing operations. For more information about internalizing Qt Quick application, see Internationalization and Localization with Qt Quick. Your software can become internationalized in the stages described in the following sections. ![]() Writing cross-platform international software with Qt is a gentle, incremental process.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |