Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ILocaleDiscovery

Optional interface an asset provider implements to discover and register additional locales at runtime.
Read time 1 minuteLast updated 8 days ago

Definition

  • Type: Interface
  • Namespace: Unity.Localization
  • Assembly: UnityEngine.LocalizationRuntimeModule
public interface ILocaleDiscovery

Remarks

Implement this alongside IAssetProvider when a provider can find locales that are not known at build time, for example from data files added to a built player. Each provider in the chain is called during LocalizationSettings.InitializeAsync, before the startup locale selectors run, so a discovered locale can be chosen as the startup locale. Register discovered locales through LocalizationSettings.AddLocale; providers that only serve the locales shipped with the project do not need this interface.
Discover locales from installed data files and register each one at startup.

Examples

using System.Threading;using Unity.Localization;using Unity.Localization.Providers;using UnityEngine;using Object = UnityEngine.Object;namespace Unity.Localization.Samples{ public class DiskLocaleProviderExample : IAsyncAssetProvider, ILocaleDiscovery { public async Awaitable DiscoverLocalesAsync(LocalizationSettings settings, CancellationToken cancellationToken = default) { foreach (var code in await ReadInstalledLocaleCodesAsync(cancellationToken)) settings.AddLocale(new Locale(code)); } async Awaitable<string[]> ReadInstalledLocaleCodesAsync(CancellationToken cancellationToken) { await Awaitable.NextFrameAsync(cancellationToken); return new[] { "en", "fr", "de" }; } public async Awaitable<T> LoadAssetAsync<T>(AssetKey key, CancellationToken cancellationToken) where T : Object { await Awaitable.NextFrameAsync(cancellationToken); return null; } public void Release(Object asset) { } }}

Methods

Method

Description

DiscoverLocalesAsyncRegisters any additional locales this provider can serve.