DefGlot - Localization / Translation

Add support for localization in your project.

I’m certain others have better systems of doing this already but not publicly released. Feel free to share and contribute!

This is not 100% ready for every kind of thing you may want to localize but I’ll be adding support for more text elements in next few days or today depending on my time.

Long term goal with DefGlot is to also build up a library of common strings in as many languages as possible. With enough coverage then the cost burden of localization of a project is much lower, and for games with simple menus and minimal unique text they can have their games mostly already translated just by using it.

8 Likes

Cool! Thanks for sharing. One improvement could be to add support for label components. Maybe have defglot.set_node_text() and defglot.set_label_text() or figure out in defglot.set_text() if running from a gui or go and depending on the context either use gui.set_text() or label.set_text().

1 Like

Any idea about detecting if it’s in a GUI context? I was thinking a pcall to a gui function but it looks like they all require a valid node so they’d still fail in GUI context without a dummy node setup.

gui.hide_keyboard() is only one I can find that doesn’t require a node and probably would be safe to use on init.


local function is_gui_context()
	if pcall(gui.hide_keyboard) then
		return true
	else
		return false
	end
end

There’s no label.get_text what a bummer!

defglot.set_text(target, key) now works with both GUI and GO labels!

Maybe there’s a better GO only function to use instead of checking the GUI functions. I’ll look now.

go.get_id is a much better option!


local function is_gui_context()
	if pcall(go.get_id) then
		return false
	else
		return true
	end
end
1 Like

Is best way to handle localization with fonts to not try to get a font which supports every language, but to include fonts for every language which needs a special font and then use gui.set_font() when handling localization to set text nodes to the correct font for the current language?

Anyone already have tools for scanning localization files for used characters to be included in fonts? If not then need to make one which can support Chinese characters etc.

I think we usually have multiple fonts and select the one appropriate for the current language.

1 Like