Class LocalizedString
Provides a way to reference a StringTableEntry inside of a specific StringTable and request the localized string.
Inherited Members
Namespace: UnityEngine.Localization
Assembly: Unity.Localization.dll
Syntax
[UxmlObject]
[Serializable]
public class LocalizedString : LocalizedReference, ISerializationCallbackReceiver, IVariableGroup, IVariableValueChanged, IVariable
Examples
This example shows how to localize a MonoBehaviour so that it updates automatically when the active locale changes. This example uses asynchronous loading to load the localized assets in the background.
This example shows how to localize a MonoBehaviour immediately. This example uses synchronous loading, which may cause a pause when first loading the localized assets.
This example shows how to localize a ScriptableObject to represent a quest in a game.
This example shows how to use local variables to represent a health counter.
This example shows how to bind to a UI Toolkit property. Note that this requires Unity 2023.2 and above.
This example shows how to use local variables when you bind to a UI Toolkit property. Note that this requires Unity 2023.2 and above.
Constructors
| Name | Description |
|---|---|
| LocalizedString() | Initializes and returns an empty instance of a LocalizedString. |
| LocalizedString(TableReference, TableEntryReference) | Initializes and returns an instance of a LocalizedString. |
Properties
| Name | Description |
|---|---|
| Arguments | Arguments that will be passed through to Smart Format. These arguments are not serialized and will need to be set at runtime. See Add(string, IVariable) to add persistent serialized arguments. |
| Count | Returns the number of local variables inside this localized string. |
| CurrentLoadingOperation | The current loading operation for the string when using StringChanged or null if one is not available. A string may not be immediately available, such as when loading the StringTable asset, so all string operations are wrapped with an UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle. See also RefreshString() |
| CurrentLoadingOperationHandle | The current loading operation for the string when using StringChanged or default if one is not available. A string may not be immediately available, such as when loading the StringTable asset, so all string operations are wrapped with an UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle. See also RefreshString() |
| HasChangeHandler | Returns true if StringChanged has any subscribers. |
| IsReadOnly | Implemented as part of the IDictionary interface but not actually used. Will always return false. |
| this[string] | Gets or sets the IVariable with the specified name. |
| Keys | Returns a collection containing all the unique local variable names. |
| Values | Returns all the local variables for this localized string. |
Methods
| Name | Description |
|---|---|
| Add(KeyValuePair<string, IVariable>) | Adds a new Local Variable to use during formatting. |
| Add(string, IVariable) | Adds a new Local Variable to use during formatting. |
| Cleanup() | |
| Clear() | Removes all local variables. |
| ClearChangeHandler() | |
| Contains(KeyValuePair<string, IVariable>) | Returns true if a local variable with the specified name exists. |
| ContainsKey(string) | Returns true if a local variable with the specified name exists. |
| CopyTo(KeyValuePair<string, IVariable>[], int) | Copies the local variables into an array starting at |
| ForceUpdate() | |
| GetEnumerator() | Returns an enumerator for all local variables in this localized string. |
| GetLocalizedString() | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. Uses WaitForCompletion to force the loading to complete synchronously. Please note that WaitForCompletion is not supported on WebGL. |
| GetLocalizedString(IList<object>) | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. |
| GetLocalizedString(params object[]) | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. Uses WaitForCompletion to force the loading to complete synchronously. Please note that WaitForCompletion is not supported on WebGL. |
| GetLocalizedStringAsync() | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. |
| GetLocalizedStringAsync(IList<object>) | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. |
| GetLocalizedStringAsync(params object[]) | Provides a translated string from a StringTable with the TableReference and the translated string that matches TableEntryReference. |
| GetSourceValue(ISelectorInfo) | The value that will be used when the smart string matches this variable. This value can then be further used by additional sources/formatters. |
| Initialize() | |
| RefreshString() | Provides a way to force a refresh of the string when using StringChanged. |
| RegisterChangeHandler(ChangeHandler) | |
| Remove(KeyValuePair<string, IVariable>) | Removes a local variable with the specified key. |
| Remove(string) | Removes a local variable with the specified name. |
| Reset() | Clears the current loading operation. |
| TryGetValue(string, out IVariable) | Gets the IVariable with the specified name. |
| Update(in BindingContext) | Extracts the localized string from the LocalizedString and applies the value to the bound target and field. |
Events
| Name | Description |
|---|---|
| StringChanged | Provides a callback that will be invoked when the translated string has changed. The following events will trigger an update:
|
| ValueChanged | This event is sent when the global variable has changed or wishes to trigger an update to any LocalizedString that is currently using it. |