Topic was automatically imported from the old Question2Answer platform.
Asked By
earlroxas
Old Version
Published before Godot 3 was released.
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.
AFAIK, there is no way but reloading scene or reassign all text values again.
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():
get_node("/root/global").setLangue("fr")
langues()
if get_node("buttonEn").is_pressed():
get_node("/root/global").setLangue("en")
langues()
func langues():
mylangue = get_node("/root/global").getLangue()
if mylangue == "fr":
get_node("buttonFr").set_self_opacity(1.0)
get_node("buttonEn").set_self_opacity(0.5)
get_node("yourNode").set_text("c'est en français")
else:
get_node("buttonEn").set_self_opacity(1.0)
get_node("buttonFr").set_self_opacity(0.5)
get_node("yourNode").set_text("this is english")
Then on a press of a button (or something else) you can change language.
Voilà.
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.