Understand when localized content loads synchronously and when it must load asynchronously.
Every accessor in Localization comes in two forms: a synchronous call that returns the value directly, and an asynchronous one that returns an Awaitable and accepts a CancellationToken. For example, use GetLocalizedString for the synchronous form and GetLocalizedStringAsync for the asynchronous form. For more information about CancellationToken, refer to CancellationToken (Microsoft).
A synchronous call succeeds when everything it needs is already loaded or can load without waiting. That depends on the content source serving the value:
Resources folder source loads both ways.When a synchronous call can’t produce the value, it returns nothing and you must request the content asynchronously instead.
// The synchronous call returns the value directly when the content can load synchronously.
string value = scoreText.GetLocalizedString();
Event-driven paths, such as StringChanged, components, and UI Toolkit bindings, follow the PreferredLoading setting:
| Value | Description |
|---|---|
| Asynchronous | Values resolve in the background and arrive through events. The default. |
| Synchronous | Values resolve immediately when they can. When a value can’t resolve synchronously, it falls back to the asynchronous path rather than failing. |
Synchronous loading keeps UI updates on the same frame, but blocks on any load the source performs.
The first request triggers initialization automatically. To front-load it, for example behind a splash screen, await InitializeAsync:
await LocalizationSettings.InitializeAsync();
Localization raises InitializationCompleted when initialization finishes.