3
\$\begingroup\$

My game can translate keys into 3 different languages (English, Chinese, Japanese)

I verified that each translation works using the "test" feature in project settings.

I want to add buttons in game that changes the language of the game into one of the three languages, i.e., there will be a button labelled "English", which when pressed turns all text into English etc.

I found that this can be done by modifying the "locale" value in a "Translation" class (documentation) However, when I try to use the Translation class's functions in code, it gives me a syntax error Non-static function "get_locale" can only be called from an instance (I am calling it from the player object, but as far as I can tell, there is no way to instantiate "Translation" since it cannot be added as a child node)

I see people changing the in game language of their games like in this video, so obviously it is possible to change the current language at run time but nobody anywhere has said how that can be done.

\$\endgroup\$
1
  • \$\begingroup\$ The error message you cite is a very standard one. Did you try getting access to an instance of the translation class to set the locale field on? \$\endgroup\$
    – DMGregory
    Commented May 12, 2022 at 2:40

1 Answer 1

3
\$\begingroup\$

The Translation is a Resource. You are supposed to have one for each language you support. So each translation is a different instance, and the get_locale method might help you identify which instance you got… You need an instance to begin with to call it.

You can set the different translations in project setting, in the localization tab. See Internationalizing games.

I'm going to presume you have already done that, since you claim the translation is already working. In that case. I'm guessing that what you want is to talk with TranslationServer, which you don't have to instantiate, and has get_locale and set_locale method.

The idea is that you would have some menu in the game where the user can pick the translation they want from a list, and depending on the option the user picked, you call set_locale with the appropriate parameter. For example, for English it would be:

TranslationServer.set_locale("en")

You can see in the video you linked that they use TranslationSever near the end (link).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .