[SOLVED] How do I set the game localization?

I’ve checked the API and the guides here on how to localize the game. I’ve made the JSON with the supported languages, and I can see the translations in the Editor.

However, I am not sure on how to activate or select a preferred locale at runtime. For example, my game runs on Facebook, which can tell me the locale of the player, e.g. ‘en_US’. Which method should I call and pass it this param, so that the game would be shown in that language?

On the same topic, is there a default language? Sort of a fallback, if a user’s locale is not supported by my game.

Hi @LeXXiK,

Here are the methods available for the Localization API:

https://developer.playcanvas.com/en/api/pc.I18n.html

You can use plain JS in a Playcanvas script to grab the url param holding the Facebook locale.

From there you can use findAvailableLocale to check if this locale is available in your game and then use the locale property to set the active locale.

this.app.i18n.locale = 'en-US';

About the default language I am not aware how this works, maybe @will or @vaios can contribute on this.

1 Like

Hi @Leonidas,

You are always as helpful :slight_smile: Yes, I checked pc.i18n, but should have been more careful in reading. I saw locale as a property, and didn’t think it would fire an event on change. Was looking for a method. I can use it. Thank you!

Nevermind about the default language, I suppose. I can set the default one in script after findAvailableLocale returns.

You are welcome!

Yes quite often changing the value of a property in a Playcanvas class can execute a method as a response:

For default locales there is a list for a number of languages on how their fallbacks work here:

1 Like

Hello all, I’m using localization in my project and its unclear for me how to use findAvailableLocale(). What is there supposed to be in the second parameter, the dictionnary? is it the available language that I did already set in the engine settings? Thanks for the support

I’m not convinced that should be public API :thinking:

AFAIK, you don’t need to call that function manually as all it does is check if the locale you are looking for is in the availableLocales and if not, checks if the fallback languages are in there.

What are you trying to do?

1 Like