Right now I querry localized strings in my project like this:
var op = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("Text", "CONFIRM_RESET_GAME");
if(op.IsDone)
confirmDialogText.text = op.Result;
else
op.Completed += (opHandle) => confirmDialogText.text = opHandle.Result;
It works, but using this pattern multiple times in my code is a little bit cumbersome.
I would like to just get the string without having a callback function everywhere.
Is there some way to ensure that all strings will be available immediately (aka op.IsDone will always be true)? Like some kind of synchronous initialization in Start() or something like that?
IsDone should always be true after preloading. You will need to wait for LocalisationSettings.InitializationOperation to complete. This could be done in start. When the selected locale is changed you will need to wait for preloading to complete again.
I have a persistent scene with an object called GameManager (with script GameManager). In Start() of GameManager I use this code:
Start() {
...
yield return LocalizationSettings.InitializationOperation;
// Line X
So when I want to load scene “A”, I first load the persistent scene and then scene “A” additively. Is my assumption correct that the line after the “yield” (Line X) will only be executed once all localized strings have been loaded?
Does this mean ALL localized strings are immediately available in my scripts in scene “A?”
One additional question: You said I have to wait again for InitializationOperation when I change the locale. How would a code look like when I changed the selected locale?
You can use LocalizationSettings.SelectedLocaleChanges to get a notification and then wait on the initialization operation again. The LocalizedString class.is really good as.it handles all of this for you,. just subscribe to the String changed event.
Yes thats fine. Selected locale gets called after the initialization operation so you should not need a coroutine as everything should be available if preloading is enabled.
Hello, I’m currently facing the same issue on iOS. I have the ‘Preload All Tables’ option checked in the Table editor (Localization Tables → Edit Table Collection → Edit Table Metadata) but the GetLocalizedStringAsync operation’s isDone is false. I have tried Cleaning All and rebuilding the Addressable Groups. Any suggestions what should I try next? I am running Unity 2020.3.14f1, Addresables 1.19.15 and Localization 1.1.1.