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

LocalizedString

class in Unity.Localization

/

Inherits from:Unity.Localization.LocalizedEntry_1


Implements interfaces:IVariable

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

Description

A serializable reference that resolves and formats a localized text value.

A LocalizedString extends LocalizedEntry<T0> to resolve an IStringEntry and return its formatted text. Smart entries are formatted through Smart Strings, with placeholders such as {score} resolved against the reference's LocalizedString.LocalVariables, and the resolved value is passed through the locale's post-processing hook before it is returned. Resolve the value with LocalizedString.GetLocalizedStringAsync, or read it synchronously with LocalizedString.GetLocalizedString once the table is loaded. Subscribe to LocalizedString.StringChanged to receive the value immediately and again whenever the selected locale changes on LocalizationSettings.

Additional resources: LocalizationSettings, ResourceDatabase, TableReference, TableEntryReference, LocalVariablesGroup, IVariable

<para>Resolve a localized string and keep a label updated as the locale changes.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class LocalizedStringResolveExample { public void Resolve() { var greeting = new LocalizedString(); greeting.SetReference("My Strings", "HELLO"); greeting.StringChanged += value => Debug.Log(value); } } }

Properties

Property Description
LocalVariables The local variables that Smart String placeholders resolve against when this string is formatted.

Public Methods

Method Description
GetLocalizedString Resolves the localized string synchronously when the table is cached or a synchronous provider can supply it.
GetLocalizedStringAsync Resolves the localized string asynchronously, formatting it with the given arguments.
GetSourceValue Resolves this string so it can be read as a Smart String placeholder in another string.
RefreshString Re-resolves the value and pushes the result to subscribers.

Events

Event Description
StringChanged Occurs when the resolved string value changes, and once immediately when a handler subscribes.

Delegates

Delegate Description
ChangeHandler Represents a method that receives a resolved localized string value.

Inherited Members

Properties

PropertyDescription
isDirty When set to true, the binding instance updates during the next update cycle. When set to false, the binding instance updates only if a change is detected.
updateTrigger When set to BindingUpdateTrigger.EveryUpdate, the binding instance updates in every update, regardless of the data source version.
IsEmpty Whether this reference is unset and resolves to no value.
TableEntryReference The entry within the table collection that this reference resolves.
EnableFallback Whether to walk the locale fallback chain when the resolving locale has no value for this reference.
HasLocaleOverride Whether a locale override is set on this reference.
IsEmpty Whether this reference is unset and resolves to no value.
LocaleOverride The locale used to resolve this reference instead of the locale selected in the project settings.
TableReference The localization table collection that this reference resolves against.

Public Methods

MethodDescription
MarkDirty Notifies the binding system to process this binding.
OnActivated Called when the binding becomes active for a specific VisualElement.
OnDataSourceChanged Called when the resolved data source of a binding changes.
OnDeactivated Called when the binding is no longer active for a specific VisualElement.
Update Called when the binding system updates the binding.
GetEntry Resolves the entry synchronously from already-loaded tables without triggering a load.
GetEntryAsync Resolves the entry asynchronously, loading the table if it is not already available.
SetReference Sets the table and entry references together so the reference refreshes only once.
OnActivated Starts resolving the reference when it becomes active on an element.
OnDeactivated Stops resolving the reference once it is no longer active on any element.
Update Writes the resolved value to the bound field.

Protected Methods

MethodDescription
ForceUpdate Called when the reference changes so subclasses can refresh any live listeners.
ResolveOverrideLocale Resolves the override locale from the project settings for subclasses to pass to the resource database.

Static Methods

MethodDescription
GetGlobalLogLevel Gets the global log level for all binding failures.
GetPanelLogLevel Gets the log level for binding failures on a panel.
ResetPanelLogLevel Resets the log level for binding failures on a panel to use the global setting.
SetGlobalLogLevel Sets the log level for all binding failures.
SetPanelLogLevel Sets the log level for binding failures on a panel.