正常情况下,文本翻译文件会被编译到应用中。 二进制翻译使应用程序不含文本翻译,该文件可编程到闪存中或存储在SD卡等存储设备上。 在处理大量翻译文件时,为应用开发者带来了更大灵活性。
配置文本转换器

安装二进制翻译
- FrontendApplication.hpp
-
- #include
- #include
- #include
- #include
- #include
- #include
- #include
-
- uint8_t fontdata[10000];
- FileDataReader reader;
- FontCache fontCache;
- CachedFont cachedFont; //Cached Font object
- //read the translation into this global array
- uint8_t translation[10000];
-
- LOCATION_PRAGMA_NOLOAD("TouchGFX_Cache")
- uint16_t Cache[1024 * 604] LOCATION_ATTRIBUTE_NOLOAD("TouchGFX_Cache");
-
- FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
- : FrontendApplicationBase(m, heap)
- {
- #ifdef SIMULATOR
- const uint32_t cacheSize = 0x300000; //3 MB, as example
- uint16_t* const cacheStartAddr = (uint16_t*)malloc(cacheSize);
- Bitmap::setCache(cacheStartAddr, cacheSize, 4);
- #else
- Bitmap::setCache(Cache, sizeof(Cache));
- #endif
-
- //read the translation from a file, or change array to a pointer that points
- //to the translation data in internal or addressable external flash
- FILE* file = fopen("generated/texts/binary/LanguageGb.bin", "rb");
- if (file)
- {
- //read data from file
- fread(translation, 1, 10000, file);
- fclose(file);
-
- //replace empty translation with the binary data
- Texts::setTranslation(GB, translation);
-
- //always change language to get TouchGFX changed from the
- //empty translation compiled in to the binary translation
- Texts::setLanguage(GB);
- }
-
- //setup the font cache with buffer and size; and file reader object
- fontCache.setMemory(fontdata, sizeof(fontdata));
- fontCache.setReader(&reader);
- TypedText text = TypedText(T___SINGLEUSE_2OJQ);
- fontCache.initializeCachedFont(text, &cachedFont);
-
- //replace the linked in font in TouchGFX with cachedFont
- TypedTextDatabase::setFont(Typography::DEFAULT, &cachedFont);
-
- Unicode::UnicodeChar* str = const_cast
(text.getText()); - fontCache.cacheString(text, str);
- }
运行模拟器
