I searched the forum and couldn’t find the info in one place, thought I’d put it together in one post.
In the current project I use the following method:
-
Split your font into 2 fonts: europe font and cjk font
-
For CJK use only the characters you need, not the whole font. (A situation where text is only displayed. Users do not write text via input.)
to switch fonts just use gui.set_font()
, example:
local function updateFont(self)
local font_name = "main"
if (global.defaultLanguage == 'ja') then
font_name = "japanese"
end
local listTextFields = {
"text_field1",
"text_field2",
"text_field3"
}
for k, v in pairs(listTextFields) do
gui.set_font(gui.get_node(v), font_name)
end
end
to get unique characters you can use the following function (thanks @Dragosha )
local function uniqueSymbols(mytexttable)
local unique={}
local extra_characters=""
for k,v in pairs(mytexttable) do
if v then
utf8.gsub(v,".", function(c)
if not unique[c] then
unique[c]=1
extra_characters=extra_characters..c
else
unique[c]=unique[c]+1
end
end)
end
end
print(extra_characters)
end
(dont forget to fetch utf8 lib, for example I use this one by @d954mas)
I’ve also attached a little demo (en / ja languages) where you can see how it works:
test_CJK_font.zip (3.9 MB)
also, if there is not much text in the game, you can use one font file, but for this you need to merge into one ttf / otf file. Has anyone tried this method? What tools can be used?