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

ResourceDatabase.GetLocalizedString

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 string GetLocalizedString(TableReference tableRef, TableEntryReference entryRef, Locale locale, Object[] args, 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.
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

string The formatted localized string, or null when the table is not loaded or the entry has no value.

Description

Resolves a localized string synchronously, or null when it cannot be resolved without an asynchronous load.

This is the synchronous companion to ResourceDatabase.GetLocalizedStringAsync. It resolves from tables already cached for the locale, and otherwise loads the table through any provider that implements ISynchronousAssetProvider (direct references or a Resources load); a table that only a purely asynchronous provider can supply resolves to null until it is loaded. Use it on the main thread when you cannot await. Smart entries are formatted and the locale post-processing hook is applied like the async form.

<para>Reads an already-loaded string without awaiting.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class GetLocalizedStringSyncExample { public void Run() { string label = LocalizationSettings.ResourceDatabase.GetLocalizedString("UI Text", "play-button"); if (label != null) Debug.Log(label); } } }