Qt allows you to load language translation files into an application at run-time. The result is that application text (i.e., screen titles, field labels, help files, etc.) will be displayed in the language of the translation file. Qt handles this internally by using a tr() function. This function wraps any literal text found in an application and allows for dictionary lookup and replacements to be performed at run time. These tr()'s are also used to identify text needed to build the translation files.
There are two files used for the translation process. The first is a .ts file, and the second is a .qm file.
The .ts file is the translation source files. This file is an XML based file which can be updated and edited using the lupdate and Qt Linguist tools. Every instance of text in an application that is translated has its own context, source, and translation field. The context changes usually from screen-to-screen and allows you to have two identical texts translated differently in different contexts. The translation field includes the text you want to show in place of the source text for a given context.
The .qm file is created from the .ts file using the lrelease tool and is a more compact and efficient file used by the application at run-time. Once the .qm file is generated, the xTuple application can be made to use it simply by using the system's Locale configuration. In practice, when a user logs into xTuple using a specified Locale, the language (i.e., translation) corresponding to that Locale will be displayed. In addition, the application supports the placement of a translation file called default.qm in the same directory as the executable. If a system is set up this way, OpenMFG will use that default file and no additional configuration will be required.
Generating a translation (.ts) file
Qt provides tools for generating translation files. This is discussed both with Qt's documentation and in other documents for xTuple. Because of the way the project files are organized it is not obvious on how to use Qt's lupdate tool to create or update a translation file. This document briefly discusses the steps to overcome this. There are still some potential problems, foremost that openrpt is not included in the translation.
To start we need to generate a project file that lupdate can use to process the code. This file must include all the source files in one project file and since this can change over time it is best and easy to generate the file when needed. To generate the file you may use qmake. The following command generates a project file that is usable for our needs and should be run in the projects top level directory, xtuple for example.
qmake -project -o ts.pro
Now that we have a project file called ts.pro we can run lupdate to update all the existing translation files that are in the code directories. If you want to add a new file you can edit the ts.pro file and add the required files to the list at the bottom of the project file.