9.6 tr() and Internationalization
If you are writing a program that will ever be translated into another language (internationalization), Qt Linguist and Qt translation tools have already solved the problem of how to organize and where to put the translated strings. To prepare our code for translation, we use QObject::tr() to surround any translatable string in our application. The tr() function is generated for every QObject and places its international strings in its own "namespace," which has the same name as the class.
tr() serves two purposes:
- It makes it possible for Qt's lupdate tool to extract all of the translatable string literals.
- If a translation is available, and the language has been selected, the strings will actually be translated into the selected language at runtime.
If no translation is available, tr() returns the original string.
For a much more complete guide to internationalization, we recommend [Blanchette06], written by one of Linguist's lead developers.