Localization
The current article describes how to localize the GUI of your project.
Fonts
Fonts files are used to correctly display characters of local languages in the Unigine-based project. The font file has a True Type font format and contains all of the local language characters.
To avoid incorrect display of language characters, you should add all of the required font files to your project folder and use the engine.gui.setFont() function when it is necessary to change the font. For example, to translate into Chinese, you should load your English-Chinese dictionary and set the corresponding font as follows:
engine.gui.setFont("my_project/gui/font_ch.ttf");
If the project supports your local language only, you can simply replace 2 font files font.ttf (for GUI widgets) and console.ttf (for console) in the data/core/gui directory with the font files containing the local language characters. The names of Unigine files should be preserved.
Character Encoding
All of the project files should be saved in UTF-8 encoding.
Translation Dictionaries
To support several languages in your project, you need to use dictionaries, which are stored in the XML format. They are used to translate the GUI from one language into another.
File Format
<?xml version="1.0" encoding="utf-8"?>
<dictionary version="1.00">
<msg>
<src>Source string</src>
<tr>Translated string</tr>
</msg>
</dictionary>
- src - a source string to be translated.
The punctuation marks should be included to the string; otherwise the string won't be translated.
- tr - a translation.
Managing Locale
To add the dictionary, use the engine.gui.addDictionary() function. To save the last loaded dictionary, use the engine.gui.saveDictionary() function. This function also allows you to save the currently loaded dictionary into another file. If you want to modify the dictionary, you can edit the XML file manually or by using the Xml class functions and then load it.
engine.gui.addDictionary("my_project/locale/my_project.ch"); // load English-Chinese dictionary
ui.updateWidgets();
Input Methods
Unigine supports IMEs (Input Method Editors) that allow entering Chinese, Japanese and Korean characters by using the Latin keyboard.
To enter Chinese, Japanese or Korean characters, simply change your keyboard layout and start typing.