Language options

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Babako

Hello, I’m making language settings in options menu for my game. I want to have a choise between english and german language. For each text in my game I have an english and a german variant but one of these text variant is hidden depending on the choice in the options menu.
I have three scenes in my game. Scene number one is the main menu. Scene number two is the options menu and scene number three is the game. What I want to do? If I choise the english variant in the options menu every german text in all scenes should be hidden and every english text in all scenes should be revealed. Could you help me please? I’m beginner in Godot. Thank you.

:bust_in_silhouette: Reply From: godot_dev_

How I would approach this is defining a global Language enum variable lang to store what language you are using. I would then define a dictionary d that stores the mapping between translations. For example, d["Hello World"] = "the german translation", this way its legible and you can easily verify the translations are properly mapped. Then, via scripting and exported variables (suppose the text field’s exported variable is named text2 that should hold the english text you want to display), every time you have a text field, define the English text that should be displayed in text2. In the _ready function of the text element, when lang=Language.English, you simply update the text field with the value of text2 (self.text = text2). When lang=Language.German, you use the german equivalent using the d (self.text = d[text2]).

So this is a data driven approach, and you will only need to maintain the global definition of d and make sure when you add a text field, it’s text2 member is properly referring to text definition keys in d.