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

ResourceDatabase.GetLocalizedStringAsync

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

Declaration

public Awaitable<string> GetLocalizedStringAsync(TableReference tableRef, TableEntryReference entryRef, Locale locale, Object[] args, CancellationToken cancellationToken, bool enableFallback, IVariableGroup localVariables);

Parameters

Parameter Description
tableRef The reference to the table collection that holds the entry.
entryRef The reference to the string entry to resolve.
locale The locale to resolve in; null uses the selected locale.
args 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

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

Description

Resolves a localized string, applying Smart formatting and the locale post-processing hook.

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.

<para>Resolves a Smart String that inserts the player's score.</para>

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