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?
Basically, im just getting the current local from browser and I want to pass that along to playcanvas and make sure I’m endin with one of the few supported langage I did setup using the localization system + jsons files
Thanks for the support
I’m not convinced that should be public API
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.
For what you are trying to do, you would somehow need to find the locale for the browser and then switch languages in the game.
Getting the browser locale should be doable via https://developer.mozilla.org/en-US/docs/Web/API/NavigatorLanguage/language
Then you can change it via: https://developer.playcanvas.com/en/api/pc.I18n.html#locale
Well, lets say I get ‘it’ (italian) from browser
And I have ‘fr’ & ‘en’ setup using 2 json files.
If I assign ‘it’ directly to locale, then I will be in a faulty state. System will not find anything related to italian. Worse, I loose the capacity to fallback on the default en-us value.
There must be something in between that will send me the fallbacks…?
I mean I can code it by hand for sure using conditional code. But isnt all this stuff already in L18n?
This should be better documented.
On my phone at the moment so bear with me.
Using your example above, if you set to Italian and there are no Italian localised data, then it fallbacks to any related language and if it can’t find any, it fallbacks back ‘en-US’.
From the engine code this is handled internally so you shouldn’t have to worry as long as you have en-US localised text.
Let me know if there are still issues as I’m purely going by the engine code
So turns out looking at the code that setting ‘locale’ will do all the work, my fallback case wasnt happening because I didnt have a ‘en-US’ setup (json file). Thank you for the support, it works fine now.