docs.unity3d.com
    Show / Hide Table of Contents

    Class LocalizationSettings

    The localization settings is the core component to the localization system. It provides the entry point to all player based localization features.

    Inheritance
    Object
    Object
    ScriptableObject
    LocalizationSettings
    Inherited Members
    ScriptableObject.SetDirty()
    ScriptableObject.CreateInstance(String)
    ScriptableObject.CreateInstance(Type)
    ScriptableObject.CreateInstance<T>()
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.Localization.Settings
    Syntax
    public class LocalizationSettings : ScriptableObject, IReset, IDisposable

    Properties

    AssetDatabase

    The asset database is responsible for providing localized assets.

    Declaration
    public static LocalizedAssetDatabase AssetDatabase { get; set; }
    Property Value
    Type Description
    LocalizedAssetDatabase

    AvailableLocales

    Declaration
    public static ILocalesProvider AvailableLocales { get; set; }
    Property Value
    Type Description
    ILocalesProvider

    HasSettings

    Indicates if there is a LocalizationSettings present. If one is not found then it will attempt to find one however unlike Instance it will not create a default, if one can not be found.

    Declaration
    public static bool HasSettings { get; }
    Property Value
    Type Description
    Boolean

    true if has settings; otherwise, false.

    InitializationOperation

    The localization system may not be immediately ready. Loading Locales, preloading assets etc. This operation can be used to check when the system is ready. You can yield on this in a coroutine to wait. If InitializeSynchronously is true then this operation will complete synchronously the first time it is called. Uses WaitForCompletion to force the loading to complete synchronously. Please note that WaitForCompletion is not supported on WebGL and InitializeSynchronously will be ignored when running on WebGL.

    Declaration
    public static AsyncOperationHandle<LocalizationSettings> InitializationOperation { get; }
    Property Value
    Type Description
    AsyncOperationHandle<LocalizationSettings>
    Examples

    This shows how to use a coroutine to wait for the Initialization Operation to complete.

    public class InitializationOperationExampleAsync : MonoBehaviour
    {
    IEnumerator Start()
    {
        yield return LocalizationSettings.InitializationOperation;
    
        Debug.Log("Initialization Completed");
    }
    }

    This shows how to use the Completed event to get a callback when the Initialization Operation is complete.

    public class InitializationOperationExampleAsyncEvent : MonoBehaviour
    {
    void Start()
    {
        var init = LocalizationSettings.InitializationOperation;
        init.Completed += a => Debug.Log("Initialization Completed");
    }
    }

    This shows how to force the Initialization Operation to complete synchronously using WaitForCompletion. Note WaitForCompletion is not supported on WebGL.

    public class InitializationOperationExampleSync : MonoBehaviour
    {
    void Start()
    {
        // Force initialization to complete synchronously.
        LocalizationSettings.InitializationOperation.WaitForCompletion();
    }
    }

    InitializeSynchronously

    Forces the InitializationOperation to complete immediately when it is started. Uses WaitForCompletion to force the loading to complete synchronously. Please note that WaitForCompletion is not supported on WebGL and InitializeSynchronously will be ignored when running on WebGL.

    Declaration
    public static bool InitializeSynchronously { get; set; }
    Property Value
    Type Description
    Boolean

    Instance

    Singleton instance for the Localization Settings.

    Declaration
    public static LocalizationSettings Instance { get; set; }
    Property Value
    Type Description
    LocalizationSettings

    Metadata

    Returns the Localization Settings Metadata. Metadata can be used to contain additional information such as App Name localization settings.

    Declaration
    public static MetadataCollection Metadata { get; }
    Property Value
    Type Description
    MetadataCollection

    PreloadBehavior

    Determines which tables, that have been marked as preload, will be loaded during the preloading step.

    Declaration
    public static PreloadBehavior PreloadBehavior { get; set; }
    Property Value
    Type Description
    PreloadBehavior

    ProjectLocale

    When tracking property variants in a scene, any changes you make whilst in this Locale are saved into the source object instead of as a variant.

    Declaration
    public static Locale ProjectLocale { get; set; }
    Property Value
    Type Description
    Locale

    SelectedLocale

    The current selected Locale. This is the Locale that will be used by default when localizing assets and strings. Calling this when the Localization system has not initialized will force the Localization system to load all Locales before returning, see SelectedLocaleAsync for a version that will load the Locales asynchronously.

    Declaration
    public static Locale SelectedLocale { get; set; }
    Property Value
    Type Description
    Locale

    SelectedLocaleAsync

    The current selected Locale. This is the Locale that will be used by default when localizing assets and strings. If InitializationOperation has not been completed yet then this will wait for the AvailableLocales part to complete first. It will not wait for the entire InitializationOperation but just the part that initializes the Locales. See SelectedLocale for a synchronous version that will block until the Locales have been loaded.

    Declaration
    public static AsyncOperationHandle<Locale> SelectedLocaleAsync { get; }
    Property Value
    Type Description
    AsyncOperationHandle<Locale>

    StartupLocaleSelectors

    Declaration
    public static List<IStartupLocaleSelector> StartupLocaleSelectors { get; }
    Property Value
    Type Description
    List<IStartupLocaleSelector>

    StringDatabase

    The string database is responsible for providing localized string assets.

    Declaration
    public static LocalizedStringDatabase StringDatabase { get; set; }
    Property Value
    Type Description
    LocalizedStringDatabase

    Methods

    GetAssetDatabase()

    Declaration
    public virtual LocalizedAssetDatabase GetAssetDatabase()
    Returns
    Type Description
    LocalizedAssetDatabase

    GetAvailableLocales()

    Declaration
    public virtual ILocalesProvider GetAvailableLocales()
    Returns
    Type Description
    ILocalesProvider

    \

    GetInitializationOperation()

    Declaration
    public virtual AsyncOperationHandle<LocalizationSettings> GetInitializationOperation()
    Returns
    Type Description
    AsyncOperationHandle<LocalizationSettings>

    GetInstanceDontCreateDefault()

    Returns the singleton of the LocalizationSettings but does not create a default one if no active settings are found.

    Declaration
    public static LocalizationSettings GetInstanceDontCreateDefault()
    Returns
    Type Description
    LocalizationSettings

    GetMetadata()

    Returns the Localization Settings Metadata. Metadata can be used to contain additional information such as App Name localization settings.

    Declaration
    public MetadataCollection GetMetadata()
    Returns
    Type Description
    MetadataCollection

    GetSelectedLocale()

    Declaration
    public virtual Locale GetSelectedLocale()
    Returns
    Type Description
    Locale

    \

    GetSelectedLocaleAsync()

    Declaration
    public virtual AsyncOperationHandle<Locale> GetSelectedLocaleAsync()
    Returns
    Type Description
    AsyncOperationHandle<Locale>

    GetStartupLocaleSelectors()

    Declaration
    public List<IStartupLocaleSelector> GetStartupLocaleSelectors()
    Returns
    Type Description
    List<IStartupLocaleSelector>

    \

    GetStringDatabase()

    Returns the string database being used to localize all strings.

    Declaration
    public virtual LocalizedStringDatabase GetStringDatabase()
    Returns
    Type Description
    LocalizedStringDatabase

    The string database.

    OnLocaleRemoved(Locale)

    Indicates that the Locale is no longer available. If the locale is the current SelectedLocale then a new one will be found using StartupLocaleSelectors.

    Declaration
    public virtual void OnLocaleRemoved(Locale locale)
    Parameters
    Type Name Description
    Locale locale

    ResetState()

    Resets the internal state of the object so it is ready to be used again and does not contain any data left over from a previous run.

    Declaration
    public void ResetState()
    Implements
    IReset.ResetState()

    SelectLocaleUsingStartupSelectors()

    Uses StartupLocaleSelectors to select the most appropriate Locale.

    Declaration
    protected virtual Locale SelectLocaleUsingStartupSelectors()
    Returns
    Type Description
    Locale

    SetAssetDatabase(LocalizedAssetDatabase)

    Declaration
    public void SetAssetDatabase(LocalizedAssetDatabase database)
    Parameters
    Type Name Description
    LocalizedAssetDatabase database

    SetAvailableLocales(ILocalesProvider)

    Declaration
    public void SetAvailableLocales(ILocalesProvider available)
    Parameters
    Type Name Description
    ILocalesProvider available

    SetSelectedLocale(Locale)

    Declaration
    public void SetSelectedLocale(Locale locale)
    Parameters
    Type Name Description
    Locale locale

    SetStringDatabase(LocalizedStringDatabase)

    Sets the string database to be used for localizing all strings.

    Declaration
    public void SetStringDatabase(LocalizedStringDatabase database)
    Parameters
    Type Name Description
    LocalizedStringDatabase database

    Events

    OnSelectedLocaleChanged

    Called when the SelectedLocale is changed. This will be called after InitializationOperation is completed so any preloading operations will be finished.

    Declaration
    public event Action<Locale> OnSelectedLocaleChanged
    Event Type
    Type Description
    Action<Locale>

    SelectedLocaleChanged

    Event that is sent when the SelectedLocale is changed.

    Declaration
    public static event Action<Locale> SelectedLocaleChanged
    Event Type
    Type Description
    Action<Locale>
    Examples

    This shows how to keep track of the current selected Locale.

    public class SelectedLocaleChangedExample : MonoBehaviour
    {
    Locale currentLocale;
    
    void OnEnable()
    {
        LocalizationSettings.SelectedLocaleChanged += OnSelectedLocaleChanged;
    }
    
    void OnDisable()
    {
        LocalizationSettings.SelectedLocaleChanged -= OnSelectedLocaleChanged;
    }
    
    IEnumerable Start()
    {
        // Get the initial selected locale value
        var selectedLocale = LocalizationSettings.SelectedLocaleAsync;
        yield return selectedLocale;
        currentLocale = selectedLocale.Result;
    }
    
    void OnSelectedLocaleChanged(Locale locale)
    {
        currentLocale = locale;
    }
    
    void OnGUI()
    {
        if (currentLocale != null)
            GUILayout.Label("The current locale is " + currentLocale.LocaleName);
    }
    }
    In This Article
    • Properties
      • AssetDatabase
      • AvailableLocales
      • HasSettings
      • InitializationOperation
      • InitializeSynchronously
      • Instance
      • Metadata
      • PreloadBehavior
      • ProjectLocale
      • SelectedLocale
      • SelectedLocaleAsync
      • StartupLocaleSelectors
      • StringDatabase
    • Methods
      • GetAssetDatabase()
      • GetAvailableLocales()
      • GetInitializationOperation()
      • GetInstanceDontCreateDefault()
      • GetMetadata()
      • GetSelectedLocale()
      • GetSelectedLocaleAsync()
      • GetStartupLocaleSelectors()
      • GetStringDatabase()
      • OnLocaleRemoved(Locale)
      • ResetState()
      • SelectLocaleUsingStartupSelectors()
      • SetAssetDatabase(LocalizedAssetDatabase)
      • SetAvailableLocales(ILocalesProvider)
      • SetSelectedLocale(Locale)
      • SetStringDatabase(LocalizedStringDatabase)
    • Events
      • OnSelectedLocaleChanged
      • SelectedLocaleChanged
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023