CopperSpice API  1.9.1
Linguist For Developers

Programmers can mark both text strings and keyboard short cuts as targets for translation to another language such as German, French, or Russian. To generate run time text translations for a CopperSpice application the following steps are required.

  • Identify text where translations should occur (A)
  • Run lupdate to create a new TS file or update existing file (B)
  • Use the Linguist application to enter the translations (C)
  • Modify your build files to compile the TS file to a QM output (D)
  • Distribute the QM files with your application
  • Load the QM files at run time (E)

Identify text for Translation (A)

For information about how to mark the strings in your source code which should be translated refer to Modifying Your Source Code for Translation.

Running lupdate (B)

For information about this step refer to Linguist lupdate Application.

Linguist Application (C)

For information about using Linguist refer to Linguist Application.

Including Translation Files in Your Project (D)

The instructions about how to modify your CMake files to compile the TS files and generate QM files can be found in our CopperSpice Overview documentation. The following is a link to a sample project which uses multiple translation files.

Sample CMake Build Files

Loading Translations (E)

There are several ways to load the translation files and normally this will be done at program start up.

The following example shows how to use QTranslator::load() to select a translation file based on the user's system locale settings. The exact name for the QM file is concatenated and if the locale is Germany, this will result in "myApp_de.qm". This file must be located in the "resources" directory in a qrc file.

The call to QCoreApplication::installTranslator() must be done after the translation file has been loaded.

static const QString qmPath = ":/resources";
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QString prefix = "_";
QString suffix = ".qm";
QTranslator translator;
if (translator.load(QLocale::system(), "myApp", prefix, qmPath, suffix)) {
// successfully found and loaded a qm file
app.installTranslator(&translator);
}
. . .
}