I am playing around in Tab Container, and I see all the tab bars work. I could refer to them via get_node and go to each component of each tab. But then, the text name of the tab bar is directly the name you specified on the scene itself such as:
MyTabContainer
Item
Character
You will then refer to the component in each TabBar by get_node(“MyTabContainer/Item/…”) , etc.
Now, if my game is to support multiple language and I would like to change Item and Character to be the words of another language, how will I deal with get_node and such in this case? Get the references into variables first, then just change the text later or what would be the recommended way to do this?
The name of a node and the text that node displays aren’t the same thing. For convenience they’re set to the same thing, but you can change the .name without changing the .text and vice versa.
I’ve been internationalizing my game recently, and I’ve got (for example) a menu that looks like:
node name text displayed in english
--------- ---- --------------------
Continue MENU_CONTINUE Continue: [profile name]
NewGame MENU_NEWGAME New Game
Options MENU_OPTIONS Options
Quit MENU_QUIT Quit to Desktop
In each of those nodes I’ve set auto-translate on, so rather than using the text in the text box for the button, it feeds that text to tr() and uses the result.
For stuff that doesn’t have auto-translate, I still refer to things by the (english) node names I used to name them in the hierarchy, but I set their .text to a string passed through tr(). I do this in places where I’m generating text, like for equipment stat blocks that I’m stitching together. If we take an oldschool D&D example, it could be something like:
func _stat_line(key: String, val: int) -> String:
return "[p]%s: %d[/p]\n" % [tr(key), val] # Translate the key here...
func _set_stat_block(strength: int, intelligence: int, wisdom: int, dexterity: int, constitution: int, charisma: int)
var label = $CharacterSheet/StatLabel
var stats = "" # Want to build the whole BBScript string before assignment...
stats += _stat_line("STAT_STR", strength)
stats += _stat_line("STAT_INT", intelligence)
stats += _stat_line("STAT_WIS", wisdom)
stats += _stat_line("STAT_DEX", dexterity)
stats += _stat_line("STAT_CON", constitution)
stats += _stat_line("STAT_CHA", charisma)
# Assign the text all at once; the bbcode parser doesn't deal well with
# incremental updates.
label.text = stats