LocalizedString
A serializable reference that resolves and formats a localized text value.
Read time 2 minutesLast updated 7 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: LocalizedEntry<IStringEntry>
- Implements: IVariable
public class LocalizedString : LocalizedEntry<IStringEntry>, IVariable
Remarks
A LocalizedString extends LocalizedEntry<TEntry> to resolve an IStringEntry and return its formatted text. Smart entries are formatted through Smart Strings, with placeholders such as 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.
{score}Additional Resources: LocalizationSettings, ResourceDatabase, TableReference, TableEntryReference, LocalVariablesGroup, IVariable
Resolve a localized string and keep a label updated as the locale changes.
Examples
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. |
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
Member | Description |
|---|---|
| StringChanged | Occurs when the resolved string value changes, and once immediately when a handler subscribes. |
Delegates
Delegate | Description |
|---|---|
| LocalizedString.ChangeHandler | Represents a method that receives a resolved localized string value. |