Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

ILocaleDiscovery

interface in Unity.Localization

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Optional interface an asset provider implements to discover and register additional locales at runtime.

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.

Additional resources: LocalizationSettings, Locale, IAssetProvider

<para>Discover locales from installed data files and register each one at startup.</para>

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) { } } }

Public Methods

Method Description
DiscoverLocalesAsync Registers any additional locales this provider can serve.