set_locale on Android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BadMother
:warning: Old Version Published before Godot 3 was released.

I have set up a language selection menu that works on Windows but doesn’t work on the Android version. Is there a way to set the locale on Android after the game starts?

:bust_in_silhouette: Reply From: mokalux

Hello there,

Yes you can.
The way I did it:

var g_langue = ""

func _ready():
	g_langue = OS.get_locale().left(2)

	if g_langue == "fr":
		get_node(mynodelangues + "fr").set_self_opacity(1.0)
		get_node(mynodelangues + "en").set_self_opacity(0.5)
		get_node(mynodelangues + "en").set_self_opacity(1.0)
		get_node(mynodelangues + "fr").set_self_opacity(0.5)


Hope this help.


Thank you for your response. This app has a translation file with 10+ languages, so I need to be able to do something like:


And change the app locale setting regardless of the host locale.

I am not opposed to modifying my labels on scene load, I already have to do this to make sure the correct font is loaded, but I cannot have separate labels for each language. As best I can tell, Android does not easily allow the locale to be changed programmatically after runtime, so set_locale is not changing the app locale. Android developers may know a way around this, but I’m not sure what to do in Godot.

BadMother | 2017-12-10 12:34

I actually set the locale after start on android. It won’t change the labels of scenes already loaded but any other and it defines how the tr() function translates strings.

I have the feeling you try to update/save the locale in the project settings? That would only work in Windows (if at all). This is because the project settings reside in a read/only location on android.

Save the locale in a separate config in the users:// directory. Setting locales works on android. Verified on Godot 2.1.4.

wombatstampede | 2017-12-11 09:53

Thank you. After your reply I reworked some of my menu button code, and it works now. It must have been some coding error that Windows forgave but Android did not.

BadMother | 2017-12-11 12:19

Happy we could help.
B.t.w.: I found very little differences between Windows & Android when it came to coding. (Mostly file/system rights related or some ogg/mp3 playback/format hickups).

wombatstampede | 2017-12-11 14:35

:bust_in_silhouette: Reply From: BadMother

See comments, wombatstampede confirmed set_locale does work in Godot 2.1.4 and I was able to resolve this.