Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetLocalizedStringAsync(TableReference, TableEntryReference, Locale, object[], CancellationToken, bool, IVariableGroup)

Resolves a localized string, applying Smart formatting and the locale post-processing hook.
Read time 1 minuteLast updated 13 days ago

Definition

  • Type: Method
  • Namespace: Unity.Localization
  • Assembly: UnityEngine.LocalizationRuntimeModule

GetLocalizedStringAsync(TableReference, TableEntryReference, Locale, Object[], CancellationToken, bool, IVariableGroup)

public Awaitable<string> GetLocalizedStringAsync(TableReference tableRef, TableEntryReference entryRef, Locale locale = null, object[] args = null, CancellationToken cancellationToken = default, bool enableFallback = true, IVariableGroup localVariables = null)

Parameters

The reference to the table collection that holds the entry.

The reference to the string entry to resolve.

locale

The locale to resolve in; null uses the selected locale.

The Smart String arguments to format placeholders with; null when the entry takes no arguments.

cancellationToken

The token that cancels the load operation.

enableFallback

Whether to walk the locale fallback chain when the locale has no value.

localVariables

The extra variables that Smart String placeholders resolve against, in addition to the arguments.

Returns

Type

Description

Awaitable<string>The formatted localized string, or null when the entry is not a string entry or has no value.

Remarks

The entry loads through the provider chain, following the locale fallback chain when
enableFallback
is true. When the entry is marked as Smart, the value is formatted with the settings' Smart formatter (see LocalizationSettings.GetSmartFormatter) using
args
and
localVariables
. The result is then passed through the locale's post-processing hook, which pseudo-locales use to transform text. To read an already-loaded value without awaiting, use ResourceDatabase.GetLocalizedString.
Resolves a Smart String that inserts the player's score.

Examples

using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class GetLocalizedStringWithArgsExample : MonoBehaviour { async void Start() { // Entry "score-message" is a Smart entry: "You scored {0} points" string message = await LocalizationSettings.ResourceDatabase .GetLocalizedStringAsync("UI Text", "score-message", args: new object[] { 42 }); Debug.Log(message); } }}