Language Support
Language Support
CDP Studio GUI and WASM applications have built-in support for translatable user interfaces.
It works like this: The UI application will match an 'original text' and replace it with a translated text whenever a text is displayed.
A simple-to-use integrated language extraction tool generates Microsoft Excel 2010 compatible .xlsx file(s) containing sheets for 'Alarm Texts' and 'UI Texts'. LibreOffice, Microsoft Excel, and compatible products can be used to handle these files. Each sheet in the file contains columns for the original text, translated text, and comments:
Example translation file
The texts to translate are extracted from all application alarms, *.ui and *.qml files in the system.
You can easily export the translations multiple times without touching the existing matching translations; instead, the tool adds new and removes missing texts.
It is also easy to import the translated files so that the GUI application(s) can utilize the translations.
Note: The language extract/import functionality requires that Python3 is installed, and that the modules tqdm and openpyxl have been pip installed, for instance by typing
pip3 install tqdm openpyxl
How to Export Translations from a System
First, make sure that the UI is updated so that only translatable text is marked for translation. When the GUI application(s) are ready to be translated, go to the CDP Studio 'Tools' menu, select 'External' and then select 'Export System Translation(s)':
This will scan all applications in the selected CDP Studio System, while simultaneously outputting information into the General Messages pane. It will extract unique alarm and user interface texts and generate them into files in the CDP Studio System directory:
- To be able to update existing translations, the directory is first scanned to find '<SystemName>_translation_*.xlsx' files
- If no '<SystemName>_translation_*.xlsx' files are found, a file called '<SystemName>_translation_Language.xlsx' is created and filled with alarm and UI texts. After the export is done, you should rename this file to the target language, for instance '<SystemName>_translation_Chinese.xlsx'. If you intend to translate to multiple languages, copy and rename each copy of this file to the wanted language in the same manner as shown above. When you are done, you might have multiple '<SystemName>_translation_<language>.xlsx' files in the CDP Studio system directory.
- If '<SystemName>_translation_*.xlsx' files are found, they are each updated with alarm and UI texts from the system. New texts are added, removed texts are removed, and unchanged texts keep their translation (if any).
The .xlsx file(s) can now be translated; This is usually done by a translation agency, but it might also be possible to use google translate or similar (It is advisable to do a reverse translation of the translation to verify that you get the expected original phrase back).
Note: Do not make changes to the texts in the "Original Text" column in the .xlsx file(s). Any changes to the original text should be made in the CDP Studio system, and then the translation(s) should be re-exported after the changes are done.
Importing Translation Files
When the .xlsx files above have been translated, first copy them into the system by overwriting the old exported .xlsx files in the CDP Studio system directory. Then go to CDP Studio 'Tools' menu, select 'External' then select 'Import System Translation(s)'. The System directory will now be scanned for '<SystemName>_translation_<Language>.xlsx' files. For each file found, a <Language>.qm file is generated into all UI application folders found.
Below is an example translation import log.
--- Processing Translations... Processing language 'Norwegian' from '/home/user/Projects/Cranes/systems/CraneControl/CraneControl_translation_Norwegian.xlsx'... Generating .ts files for translation... Updating '/home/user/Projects/Cranes/systems/CraneControl/CraneControlGUI/Application/Norwegian.qm'... Generated 608 translation(s) (608 finished and 0 unfinished) Processing language 'Chinese' from '/home/user/Projects/Cranes/systems/CraneControl_translation_Chinese.xlsx'... Generating .ts files for translation... Updating '/home/user/Projects/Cranes/systems/CraneControlGUI/Application/Chinese.qm'... Generated 608 translation(s) (608 finished and 0 unfinished) Done. Note that intermediate *.ts files can be deleted to save space. See CDPStudio help content 'CDPStudio Design Mode' -> 'Language Support' for more information on translations.
Translation Notes
Key items to be aware of when designing translatable UI files:
- Make sure all widgets are big enough to contain the text in all languages.
- In Design mode, use the sub-property named translatable to mark strings that should not get translated:
- Translate image paths when you want different images for different languages. For instance, you can make a <language> folder that is specific to that language.
- The EventList widget (when configured with listType Active) will only perform translation of the "Text" and "Description" columns. We recommend configuring it to show Time and Alarm Text.
- To make WASM UI translation work, make sure that a .ui file contains either (invisible) Label(s), or dynamic properties, and that each contains the file name of the <Language>.qm files used; for instance, 'Norwegian.qm' without the quotes.
Key items regarding QML text translation:
- All translatable strings in .qml files must be wrapped in qsTr()
- Keep in mind that QML files are reloaded depending on the Qt version.
Note: The *.qm files can be located in the GUI Application directory, or embedded into the executable as a resource (See How to create a resource File and add a dialog).
If you want to be able to update languages without rebuilding the executable, we recommend having the generated .qm translation files in the Application directory for each GUI application (this is the default behavior). It is also possible to lock down the language files by embedding them as resources in the GUI applications. The application(s) must then be rebuilt whenever a .qm file changes for the new translations to be visible.
Note: The GUI needs widgets and/or logic for selecting the different language files. This is described in the CDP Widgets documentation (CDPBaseMainWindow class).
The translation scripts (located in the CDP Studio 'toolkits/<toolkit>/CDP<version>/scripts/translation' folder) use the 'lconvert' and 'lrelease' tools (available in the CDP Studio 'toolkits/<toolkit>/Qt<version>/bin folder) to generate the <Language>.qm files. To enable additional workflows, the intermediate *.ts files are not deleted. For instance, it could be possible to process these further by using additional tools before running 'lrelease' on the final *.ts file(s).
If you do not need the *.ts files for anything, they can be deleted.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.