This section describes how to use binary translations in
TouchGFX. Normally text translations are compiled into the
application. This principle is efficient and easy to use.
Binary translations keep the text translation out of the application. The binary translations are generated in separate binary files which can be programmed to flash or for example stored on an sdcard. This gives more flexibility to application developers when handling a large number of translations.
The Text class in TouchGFX contains a pointer array with a pointer to a translation table for each language in the application. A translation table is in principle a collection of all strings used in that language:
This table allows TouchGFX to find a given text in the selected language.
When using binary translations at runtime you change the mapping from the compiled-in translation to a binary translation. The binary translations must be available in addressable memory (flash or RAM). It can for example be loaded from a disk or written to the flash during production.
The TouchGFX text converter can be configured to generate binary translations. This is easily done in the TouchGFX Designer 4.13. Go to the Config tab, select "Text Configuration", and click "Binary translation files"
When you generate the code the next time, the binary translations will be in the generated/texts/binary folder.
The translations compiled into the application are empty when binary translations are generated. Therefore no texts are shown unless you load binary translations.
When the application has the binary translation in memory, it can install it in TouchGFX. Now TouchGFX will use that translation. Depending on the application this can be done in different places or time (The FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap) constructor in gui/src/common/FrontApplication.cpp can e.g. be used).
Here is an example where we read a translation for English from a filesystem and install it as language "GB".
Note, it is necessary to change language after installing a translation. Otherwise TouchGFX will still use the previous translation. Read about changing language here.
It is also necessary to force a redraw of the current screen, or change screen, to see the new texts (if you are loading translations for the language that is used on the display). TouchGFX does not redraw anything automatically.
The current screen can be redrawn by invalidating the root container:
This will force a redraw. In some cases it is better to change the screen to get everything set up again from scratch (e.g. to recalculate TextArea sizes). You can change the screen by creating an interaction in TouchGFX Designer with the "Change Screen" action. See this article.