Is there an elegant way to deal with multiple languages and fonts in Defold? It’s sometimes not ideal to include all chars in one font when dealing with multiple languages, each with many glyphs.
Ideally I’d like to change which font is used in a GUI at runtime, but I don’t think this is possible?
Is the only option, then, to map all text nodes in all GUIs and manually use set_font to change the font?
Thanks @sergey.lerg. The project I’m working on is HTML5, and doesn’t look supported? In any case, this is great to know for future projects, nice one.
I’m going to have to localise my game in languages that have foreign characters (russian/japanese).
All my text nodes are currently with a fond that only support traditional alphanumeric characters.
What’s the best practice at this point to localise the game? I’d rather avoid to duplicate all text nodes…
Get the system language using sys.get_sys_info().language
Store all strings in the game in one Lua table per language, each string keyed on an id:
local strings = {
en = {
menu_newgame = "NEW GAME",
},
ru = {
menu_newgame = "НОВАЯ ИГРА",
},
es = {
...
},
...
}
Look up the string to use based on the language and key
Set the string using label.set_text(label_url, text) or gui.set_text(node, text)
Change font depending on language. It is quite likely that you’re able to find a font which contains all latin characters to handle English, German, Spanish etc, another font for Cyrillic, and one for Japanese etc
OR combine all font glyphs for all supported languages in a single ttf/otf file, in which case you can skip this step completely
For gui scenes you add all fonts to the scene and use gui.set_font(label, font)
For labels store the fonts as go.property("main_ru", go.property("/assets/fonts/main_ru.font")) and use go.set(label_url, "font", font) to change font
Can be done with FontForge. Open base font. Element → Merge Fonts. Test saying no and if that doesn’t work well restart and say yes. Repeat for any languages you want. Then File → Generate Fonts to get new font of merged glyphs.