0 votes

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?

in Engine by (19 points)

2 Answers

0 votes
Best answer

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

by (19 points)
–1 vote

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)

VoilĂ .

Hope this help.


by (167 points)
edited by

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.

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.

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.

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).

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.