docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method GetLocalizedStringAsync

    GetLocalizedStringAsync(TableEntryReference, Locale, FallbackBehavior, params object[])

    Attempts to retrieve a string from the requested table. This method is asynchronous and may not have an immediate result. Check IsDone to see if the data is available, if it is false then you can use the Completed event to get a callback when it is finished, yield on the operation or call WaitForCompletion to force the operation to complete.

    Declaration
    public AsyncOperationHandle<string> GetLocalizedStringAsync(TableEntryReference tableEntryReference, Locale locale = null, FallbackBehavior fallbackBehavior = FallbackBehavior.UseProjectSettings, params object[] arguments)
    Parameters
    Type Name Description
    TableEntryReference tableEntryReference

    A reference to the entry in the StringTable

    Locale locale

    The Locale to use instead of the default SelectedLocale

    FallbackBehavior fallbackBehavior

    A Enum which determines if a Fallback should be used when no value could be found for the Locale.

    object[] arguments

    Arguments passed to SmartFormat or String.Format.

    Returns
    Type Description
    AsyncOperationHandle<string>
    Examples

    This example shows how to get a localized string from the DefaultTable of a custom locale (not the currently selected locale) and use WaitForCompletion to force it to complete.

    var customLocale = LocalizationSettings.AvailableLocales.GetLocale("fr");
    
    var stringOperation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My String", customLocale);
    
    // We can force the operation to complete.
    if (!stringOperation.IsDone)
        stringOperation.WaitForCompletion();
    
    Debug.Log(stringOperation.Result);

    This example shows how to get a localized string from the DefaultTable of a custom locale (not the currently selected locale) and use a coroutine to wait for it to complete.

    IEnumerator LoadStringWithCoroutine()
    {
        var stringOperation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My String");
    
        // We can skip waiting if the operation is already done.
        if (!stringOperation.IsDone)
            yield return stringOperation;
    
        Debug.Log(stringOperation.Result);
    }

    GetLocalizedStringAsync(TableEntryReference, IList<object>, Locale, FallbackBehavior)

    Attempts to retrieve a string from the requested table. This method is asynchronous and may not have an immediate result. Check IsDone to see if the data is available, if it is false then you can use the Completed event to get a callback when it is finished, yield on the operation or call WaitForCompletion to force the operation to complete.

    Declaration
    public AsyncOperationHandle<string> GetLocalizedStringAsync(TableEntryReference tableEntryReference, IList<object> arguments, Locale locale = null, FallbackBehavior fallbackBehavior = FallbackBehavior.UseProjectSettings)
    Parameters
    Type Name Description
    TableEntryReference tableEntryReference

    A reference to the entry in the StringTable

    IList<object> arguments

    Arguments passed to SmartFormat or String.Format.

    Locale locale

    The Locale to use instead of the default SelectedLocale

    FallbackBehavior fallbackBehavior

    A Enum which determines if a Fallback should be used when no value could be found for the Locale.

    Returns
    Type Description
    AsyncOperationHandle<string>
    Examples

    This example shows how to get a localized string from the DefaultTable and use the Completed event to display it.

    var stringOperation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My String");
    stringOperation.Completed += s =>
    {
        Debug.Log("String loaded: " + s);
    };

    GetLocalizedStringAsync(TableReference, TableEntryReference, Locale, FallbackBehavior, params object[])

    Attempts to retrieve a string from the requested table. The string will first be formatted with UnityEngine.Localization.SmartFormat if IsSmart is enabled otherwise it will use String.Format. This method is asynchronous and may not have an immediate result. Check IsDone to see if the data is available, if it is false then you can use the Completed event to get a callback when it is finished, yield on the operation or call WaitForCompletion to force the operation to complete.

    Declaration
    public virtual AsyncOperationHandle<string> GetLocalizedStringAsync(TableReference tableReference, TableEntryReference tableEntryReference, Locale locale = null, FallbackBehavior fallbackBehavior = FallbackBehavior.UseProjectSettings, params object[] arguments)
    Parameters
    Type Name Description
    TableReference tableReference

    A reference to the table to check for the string.

    TableEntryReference tableEntryReference

    A reference to the entry in the StringTable

    Locale locale

    The Locale to use instead of the default SelectedLocale

    FallbackBehavior fallbackBehavior

    A Enum which determines if a Fallback should be used when no value could be found for the Locale.

    object[] arguments

    Arguments passed to SmartFormat or String.Format.

    Returns
    Type Description
    AsyncOperationHandle<string>
    Examples

    This example shows how to get a localized string from a specified table and entry.

    var stringOperation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("My Table", "My String");
    stringOperation.Completed += s =>
    {
        Debug.Log("String loaded: " + s);
    };

    GetLocalizedStringAsync(TableReference, TableEntryReference, IList<object>, Locale, FallbackBehavior, IVariableGroup)

    Attempts to retrieve a string from the requested table. The string will first be formatted with UnityEngine.Localization.SmartFormat if IsSmart is enabled otherwise it will use String.Format. This method is asynchronous and may not have an immediate result. Check IsDone to see if the data is available, if it is false then you can use the Completed event to get a callback when it is finished, yield on the operation or call WaitForCompletion to force the operation to complete.

    Declaration
    public virtual AsyncOperationHandle<string> GetLocalizedStringAsync(TableReference tableReference, TableEntryReference tableEntryReference, IList<object> arguments, Locale locale = null, FallbackBehavior fallbackBehavior = FallbackBehavior.UseProjectSettings, IVariableGroup localVariables = null)
    Parameters
    Type Name Description
    TableReference tableReference

    A reference to the table to check for the string.

    TableEntryReference tableEntryReference

    A reference to the entry in the StringTable

    IList<object> arguments

    Arguments passed to SmartFormat or String.Format.

    Locale locale

    The Locale to use instead of the default SelectedLocale

    FallbackBehavior fallbackBehavior

    A Enum which determines if a Fallback should be used when no value could be found for the Locale.

    IVariableGroup localVariables

    Optional IVariableGroup which can be used to add additional named variables.

    Returns
    Type Description
    AsyncOperationHandle<string>
    Examples

    This example shows how to get a localized string which uses Smart String for formatting.

    // Prepare Smart String Arguments.
    var dictionary = new Dictionary<string, string>();
    dictionary.Add("title", "General");
    dictionary.Add("name", "Radahn");
    
    // Example string: "I am {title} {name}!"
    var stringOperation = LocalizationSettings.StringDatabase.GetLocalizedStringAsync("Main Characters", "General_Radahn_Intro", new object[] { dictionary });
    stringOperation.Completed += s =>
    {
        // Example output: "I am General Radahn!"
        Debug.Log(s.Result);
    };
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)