Topic was automatically imported from the old Question2Answer platform.
Asked By
grognard3
I’m experimenting with localization methods. My idea right now is to have an autoload DISPLAY script which contains blank variables for strings, and have separate language autoload scripts with each language’s translated strings. The game should replace the values in DISPLAY with the strings from the selected language’s script. So I want something like:
var language = "English"
func _ready():
#both globaldisplay.gd and English.gd are autoload scripts
globaldisplay.menutext = get(language).menutext
Obviously, this doesn’t work. I’m just not sure how I can call the English.gd script using the “language” variable. Thanks!
I wouldn’t use autoloads for each languages at all. Too much hassle to maintain. Make the various language files individual reference scripts with unique class name. Then have 1 autoloader which redirects to the correct class.
match selection:
"English": language_texts = EnglishTexts.new()
Then later in the code
dialogue1_label.text = language_texts.TEXT1
You might be able to make it work without creating a class object at all, just using the class name directly,
Thanks for the help. I tried out the class replacing, but had some trouble with a “cannot assign a new value to a constant” error. I ended up just creating a local variable which I assigned the autoload English script to, and then called that variable to replace the main script text. For my project, it doesn’t increase maintenance too much, but I’ll keep the class solution in mind to experiment with more if I need something more elegant.
grognard3 | 2021-07-15 23:04
I’m confused why you are trying to assign new values to the text consts, but if it works for you, it’s fine