0 votes

So, i've been testing the translation or localization in godot engine. If I type the id from translation in the label, the text displayed will change according to current selected locale / language.

So, what i want to do is change language using script (using TranslationServer.setlocale right?) without reloading the scene, because from what I test, the label text will change after the scene reloaded, not instantly changed when TranslationServer.setlocale called. Can i do this? Please help.

in Engine by (81 points)

AFAIK, there is no way but reloading scene or reassign all text values again.

Well, reassign all text is my last resort.

1 Answer

–3 votes

hello there,

for my projects i do this, in global.gd (for example) or anywhere you prefer.

var g_langue = ""

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

func getLangue():
    return g_langue

func setLangue(l):
    g_langue = l

Then in any scene i have 2 buttons (1 for french and another for english)

func _input(event):
    if get_node("buttonFr").is_pressed():
    if get_node("buttonEn").is_pressed():

func langues():
    mylangue = get_node("/root/global").getLangue()

    if mylangue == "fr":
        get_node("yourNode").set_text("c'est en français")
        get_node("yourNode").set_text("this is english")

Then on a press of a button (or something else) you can change language.

VoilĂ .

by (169 points)

Thanks for the answer, but it's just using settext, i know that the simplest way is using settext but doing that to all the label is very time consuming.

You shouldn't manually localize each label, but prefer using proper localization

this is a 2017 post

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.