docs.unity3d.com
  • Manual
  • Scripting API
  • Changelog
  • License
    Show / Hide Table of Contents
    • Unity​Editor.​Localization
      • Addressable​Entry​Not​Found​Exception
      • Asset​Not​Persistent​Exception
      • Asset​Table​Collection
      • Asset​Table​Collection​Extension​Attribute
      • Collection​Extension
      • Localization​Editor​Events
      • Localization​Editor​Settings
      • Localization​Project​Settings
      • Localization​Table​Collection
      • Localization​Table​Collection.​Row<TEntry>
      • String​Table​Collection
      • String​Table​Collection​Extension​Attribute
    • Unity​Editor.​Localization.​Addressables
      • Addressable​Group​Rules
      • Group​Resolver
    • Unity​Editor.​Localization.​Platform.​Android
      • Player
    • Unity​Editor.​Localization.​Plugins.​CSV
      • Csv
      • Csv​Extension
    • Unity​Editor.​Localization.​Plugins.​CSV.​Columns
      • Column​Mapping
      • Csv​Columns
      • IKey​Column
      • Key​Id​Columns
      • Locale​Columns
    • Unity​Editor.​Localization.​Plugins.​Google
      • Authentication​Type
      • Google​Sheets
      • Google​Sheets​Extension
      • IGoogle​Sheets​Service
      • New​Sheet​Properties
      • Sheets​Service​Provider
    • Unity​Editor.​Localization.​Plugins.​Google.​Columns
      • Column​Mapping
      • IPull​Key​Column
      • Key​Column
      • Key​Comment​Column
      • Key​Metadata​Column<TMetadata>
      • Locale​Column
      • Locale​Comment​Column
      • Locale​Metadata​Column<TMetadata>
      • Push​Fields
      • Sheet​Column
    • Unity​Editor.​Localization.​Plugins.​XLIFF
      • Xliff
      • Xliff.​Import​Notes​Behavior
      • Xliff.​Import​Options
      • Xliff​Document
      • Xliff​Version
    • Unity​Editor.​Localization.​Plugins.​XLIFF.​Common
      • IFile
      • IGroup
      • IGroup​Collection
      • INote
      • INote​Collection
      • ITranslation​Unit
      • ITranslation​Unit​Collection
      • IXliff​Document
      • Note​Type
    • Unity​Editor.​Localization.​Reporting
      • ITask​Reporter
      • Progress​Bar​Reporter
      • Progress​Reporter
      • Task​Timer​Reporter
    • Unity​Editor.​Localization.​Search
      • Table​Entry​Search​Data
    • Unity​Editor.​Localization.​UI
      • Localization​Tables​Window
      • Project​Locale​Popup​Field
      • Xliff​Version​Popup
    • Unity​Engine.​Localization
      • Display​Name​Attribute
      • Editor​Property​Driver
      • IPreload​Required
      • Locale
      • Locale​Identifier
      • Localized​Asset<TObject>
      • Localized​Asset<TObject>.​Change​Handler
      • Localized​Asset​Base
      • Localized​Asset​Table
      • Localized​Audio​Clip
      • Localized​Font
      • Localized​Game​Object
      • Localized​Material
      • Localized​Mesh
      • Localized​Object
      • Localized​Reference
      • Localized​Sprite
      • Localized​String
      • Localized​String.​Change​Handler
      • Localized​String​Table
      • Localized​Table<TTable, TEntry>
      • Localized​Table<TTable, TEntry>.​Change​Handler
      • Localized​Texture
      • Localized​Tmp​Font
    • Unity​Engine.​Localization.​Components
      • Localize​Audio​Clip​Event
      • Localized​Asset​Behaviour<TObject, TReference>
      • Localized​Asset​Event<TObject, TReference, TEvent>
      • Localized​Game​Object​Event
      • Localized​Mono​Behaviour
      • Localize​Sprite​Event
      • Localize​String​Event
      • Localize​Texture​Event
    • Unity​Engine.​Localization.​Events
      • Unity​Event​Audio​Clip
      • Unity​Event​Game​Object
      • Unity​Event​Sprite
      • Unity​Event​String
      • Unity​Event​Texture
    • Unity​Engine.​Localization.​Metadata
      • Comment
      • Entry​Override​Type
      • Exclude​Entry​From​Export
      • Fallback​Locale
      • IEntry​Override
      • IMetadata
      • IMetadata​Collection
      • IShared​Metadata
      • Metadata​Attribute
      • Metadata​Collection
      • Metadata​Type
      • Platform​Override
      • Preload​Asset​Table​Metadata
      • Preload​Asset​Table​Metadata.​Preload​Behaviour
      • Shared​Table​Collection​Metadata
      • Shared​Table​Entry​Metadata
      • Smart​Format​Tag
    • Unity​Engine.​Localization.​Platform.​Android
      • Adaptive​Icon
      • Adaptive​Icons​Info
      • App​Info
      • Legacy​Icons​Info
      • Round​Icons​Info
    • Unity​Engine.​Localization.​Platform.​iOS
      • App​Info
    • Unity​Engine.​Localization.​Property​Variants
      • Custom​Tracked​Object​Attribute
      • Game​Object​Localizer
    • Unity​Engine.​Localization.​Property​Variants.​Tracked​Objects
      • Json​Serializer​Tracked​Object
      • Json​Serializer​Tracked​Object.​Apply​Changes​Method
      • Tracked​Mesh​Filter
      • Tracked​Mono​Behaviour​Object
      • Tracked​Object
      • Tracked​Rect​Transform
      • Tracked​Transform
    • Unity​Engine.​Localization.​Property​Variants.​Tracked​Properties
      • Array​Size​Tracked​Property
      • Bool​Tracked​Property
      • Byte​Tracked​Property
      • Char​Tracked​Property
      • Double​Tracked​Property
      • Enum​Tracked​Property
      • Float​Tracked​Property
      • Int​Tracked​Property
      • IString​Property
      • ITracked​Property
      • ITracked​Property​Value<T>
      • Localized​Asset​Property
      • Localized​String​Property
      • Long​Tracked​Property
      • SByte​Tracked​Property
      • Short​Tracked​Property
      • String​Tracked​Property
      • Tracked​Property<TPrimitive>
      • UInt​Tracked​Property
      • ULong​Tracked​Property
      • Unity​Object​Property
      • UShort​Tracked​Property
    • Unity​Engine.​Localization.​Pseudo
      • Accenter
      • Character​Substitutor
      • Character​Substitutor.​List​Selection​Method
      • Character​Substitutor.​Substitution​Method
      • Encapsulator
      • Expander
      • Expander.​Expansion​Rule
      • Expander.​Insert​Location
      • IPseudo​Localization​Method
      • Message
      • Message​Fragment
      • Mirror
      • Preserve​Tags
      • Pseudo​Locale
      • Read​Only​Message​Fragment
      • Typical​Character​Sets
      • Writable​Message​Fragment
    • Unity​Engine.​Localization.​Settings
      • Command​Line​Locale​Selector
      • Fallback​Behavior
      • IInitialize
      • ILocales​Provider
      • IReset
      • IStartup​Locale​Selector
      • ITable​Postprocessor
      • ITable​Provider
      • Locales​Provider
      • Localization​Settings
      • Localized​Asset​Database
      • Localized​Database<TTable, TEntry>
      • Localized​Database<TTable, TEntry>.​Table​Entry​Result
      • Localized​String​Database
      • Localized​String​Database.​Missing​Translation
      • Missing​Translation​Behavior
      • Player​Pref​Locale​Selector
      • Preload​Behavior
      • Specific​Locale​Selector
      • System​Locale​Selector
    • Unity​Engine.​Localization.​Smart​Format
      • Formatting​Error​Event​Args
      • Smart
      • Smart​Extensions
      • Smart​Formatter
    • Unity​Engine.​Localization.​Smart​Format.​Core.​Extensions
      • Formatter​Base
      • IFormatter
      • IFormatter​Literal​Extractor
      • IFormatting​Info
      • ISelector​Info
      • ISource
    • Unity​Engine.​Localization.​Smart​Format.​Core.​Settings
      • Case​Sensitivity​Type
      • Error​Action
      • Smart​Settings
    • Unity​Engine.​Localization.​Smart​Format.​Extensions
      • Choose​Formatter
      • Conditional​Formatter
      • Custom​Plural​Rule​Provider
      • Default​Formatter
      • Default​Source
      • Dictionary​Source
      • Global​Variables​Source
      • Is​Match​Formatter
      • List​Formatter
      • Persistent​Variables​Source
      • Persistent​Variables​Source.​Scoped​Update
      • Plural​Localization​Formatter
      • Reflection​Source
      • Sub​String​Formatter
      • Sub​String​Formatter.​Sub​String​Out​Of​Range​Behavior
      • Template​Formatter
      • Time​Formatter
      • Value​Tuple​Source
      • XElement​Formatter
      • Xml​Source
    • Unity​Engine.​Localization.​Smart​Format.​Global​Variables
      • Bool​Global​Variable
      • Float​Global​Variable
      • Global​Variable<T>
      • Global​Variables​Group
      • IGlobal​Variable
      • IGlobal​Variable​Value​Changed
      • Int​Global​Variable
      • IVariable​Group
      • Nested​Global​Variables​Group
      • String​Global​Variable
    • Unity​Engine.​Localization.​Smart​Format.​Persistent​Variables
      • Bool​Variable
      • Byte​Variable
      • Double​Variable
      • Float​Variable
      • IMetadata​Variable
      • Int​Variable
      • IVariable
      • IVariable​Group
      • IVariable​Value​Changed
      • Long​Variable
      • Nested​Variables​Group
      • Object​Variable
      • SByte​Variable
      • Short​Variable
      • String​Variable
      • UInt​Variable
      • ULong​Variable
      • UShort​Variable
      • Variable<T>
      • Variables​Group​Asset
    • Unity​Engine.​Localization.​Tables
      • Asset​Table
      • Asset​Table​Entry
      • Detailed​Localization​Table<TEntry>
      • Distributed​UIDGenerator
      • IKey​Generator
      • Localization​Table
      • Missing​Entry​Action
      • Sequential​IDGenerator
      • Shared​Table​Data
      • Shared​Table​Data.​Shared​Table​Entry
      • String​Table
      • String​Table​Entry
      • Table​Entry
      • Table​Entry​Reference
      • Table​Entry​Reference.​Type
      • Table​Reference
      • Table​Reference.​Type
    • Scripting API
    • Unity​Engine.​Localization.​Components
    • Localize​String​Event

    Class LocalizeStringEvent

    Component that can be used to Localize a string. Provides an update event UpdateString(String) that can be used to automatically update the string when the SelectedLocale or StringReference changes. Allows for configuring optional arguments that will be used by Smart Format or String.Format.

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    LocalizedMonoBehaviour
    LocalizeStringEvent
    Inherited Members
    MonoBehaviour.IsInvoking()
    MonoBehaviour.CancelInvoke()
    MonoBehaviour.Invoke(String, Single)
    MonoBehaviour.InvokeRepeating(String, Single, Single)
    MonoBehaviour.CancelInvoke(String)
    MonoBehaviour.IsInvoking(String)
    MonoBehaviour.StartCoroutine(String)
    MonoBehaviour.StartCoroutine(String, Object)
    MonoBehaviour.StartCoroutine(IEnumerator)
    MonoBehaviour.StartCoroutine_Auto(IEnumerator)
    MonoBehaviour.StopCoroutine(IEnumerator)
    MonoBehaviour.StopCoroutine(Coroutine)
    MonoBehaviour.StopCoroutine(String)
    MonoBehaviour.StopAllCoroutines()
    MonoBehaviour.print(Object)
    MonoBehaviour.useGUILayout
    MonoBehaviour.runInEditMode
    Behaviour.enabled
    Behaviour.isActiveAndEnabled
    Component.GetComponent(Type)
    Component.GetComponent<T>()
    Component.TryGetComponent(Type, Component)
    Component.TryGetComponent<T>(T)
    Component.GetComponent(String)
    Component.GetComponentInChildren(Type, Boolean)
    Component.GetComponentInChildren(Type)
    Component.GetComponentInChildren<T>(Boolean)
    Component.GetComponentInChildren<T>()
    Component.GetComponentsInChildren(Type, Boolean)
    Component.GetComponentsInChildren(Type)
    Component.GetComponentsInChildren<T>(Boolean)
    Component.GetComponentsInChildren<T>(Boolean, List<T>)
    Component.GetComponentsInChildren<T>()
    Component.GetComponentsInChildren<T>(List<T>)
    Component.GetComponentInParent(Type)
    Component.GetComponentInParent<T>()
    Component.GetComponentsInParent(Type, Boolean)
    Component.GetComponentsInParent(Type)
    Component.GetComponentsInParent<T>(Boolean)
    Component.GetComponentsInParent<T>(Boolean, List<T>)
    Component.GetComponentsInParent<T>()
    Component.GetComponents(Type)
    Component.GetComponents(Type, List<Component>)
    Component.GetComponents<T>(List<T>)
    Component.GetComponents<T>()
    Component.CompareTag(String)
    Component.SendMessageUpwards(String, Object, SendMessageOptions)
    Component.SendMessageUpwards(String, Object)
    Component.SendMessageUpwards(String)
    Component.SendMessageUpwards(String, SendMessageOptions)
    Component.SendMessage(String, Object)
    Component.SendMessage(String)
    Component.SendMessage(String, Object, SendMessageOptions)
    Component.SendMessage(String, SendMessageOptions)
    Component.BroadcastMessage(String, Object, SendMessageOptions)
    Component.BroadcastMessage(String, Object)
    Component.BroadcastMessage(String)
    Component.BroadcastMessage(String, SendMessageOptions)
    Component.transform
    Component.gameObject
    Component.tag
    Object.GetInstanceID()
    Object.GetHashCode()
    Object.Equals(Object)
    Object.Instantiate(Object, Vector3, Quaternion)
    Object.Instantiate(Object, Vector3, Quaternion, Transform)
    Object.Instantiate(Object)
    Object.Instantiate(Object, Transform)
    Object.Instantiate(Object, Transform, Boolean)
    Object.Instantiate<T>(T)
    Object.Instantiate<T>(T, Vector3, Quaternion)
    Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
    Object.Instantiate<T>(T, Transform)
    Object.Instantiate<T>(T, Transform, Boolean)
    Object.Destroy(Object, Single)
    Object.Destroy(Object)
    Object.DestroyImmediate(Object, Boolean)
    Object.DestroyImmediate(Object)
    Object.FindObjectsOfType(Type)
    Object.DontDestroyOnLoad(Object)
    Object.DestroyObject(Object, Single)
    Object.DestroyObject(Object)
    Object.FindSceneObjectsOfType(Type)
    Object.FindObjectsOfTypeIncludingAssets(Type)
    Object.FindObjectsOfType<T>()
    Object.FindObjectOfType<T>()
    Object.FindObjectsOfTypeAll(Type)
    Object.FindObjectOfType(Type)
    Object.name
    Object.hideFlags
    Namespace: UnityEngine.Localization.Components
    Syntax
    [AddComponentMenu("Localization/Localize String Event")]
    public class LocalizeStringEvent : LocalizedMonoBehaviour
    Examples

    This example shows how a Localized String Event can be dynamically updated with a different localized string or new formatting data.

    using System;
    using UnityEngine;
    using UnityEngine.Localization;
    using UnityEngine.Localization.Components;
    
    public class LocalizeStringEventExample : MonoBehaviour
    {
    [Serializable]
    public class CharacterData
    {
       public string name;
       public string surname;
       public int age;
    }
    
    public CharacterData characterInfo = new CharacterData { name = "Guy", surname = "Threepwood", age = 17 };
    
    public LocalizeStringEvent localizedStringEvent;
    LocalizedString originalLocalizedString;
    
    // Various ways to address a string table entry
    public LocalizedString localizedString = new LocalizedString { TableReference = "My String Table Collection", TableEntryReference = "My Text 1" };
    public string tableName = "My String Table Collection";
    public string keyName = "My Text 2";
    public long keyId = 123;
    
    void Start()
    {
       // Keep track of the original so we dont change localizedString by mistake
       originalLocalizedString = localizedStringEvent.StringReference;
    
       // Assuming the Localizing String is using Smart Format:
       // The string
       // "{name} {surname} is {age} years old"
       // would produce:
       // "Guy Threepwood is 17 years old"
       localizedStringEvent.StringReference.Arguments = new[] { characterInfo };
    
       // We can add a listener if we are interested in the Localized String.
       localizedStringEvent.OnUpdateString.AddListener(OnStringChanged);
    }
    
    void OnStringChanged(string s)
    {
       Debug.Log($"String changed to `{s}`");
    }
    
    void OnGUI()
    {
       if (GUILayout.Button("Change using LocalizedString"))
       {
           // We are assigning a new LocalizedString so will need to copy the arguments across
           localizedString.Arguments = localizedStringEvent.StringReference.Arguments;
    
           // Assign the new LocalizedString, this will trigger an update
           localizedStringEvent.StringReference = localizedString;
       }
    
       if (GUILayout.Button("Change using key name"))
       {
           // Restore the original LocalizedString in case we changed it previously.
           localizedStringEvent.StringReference = originalLocalizedString;
    
           // Assign a new Table and Entry. This will trigger an update.
           localizedStringEvent.StringReference.SetReference(tableName, keyName);
    
           // We could do this if we only wanted to change the entry but use the same table
           // localizedStringEvent.StringReference.TableEntryReference = keyName;
       }
    
       if (GUILayout.Button("Change using key id"))
       {
           // Restore the original LocalizedString in case we changed it previously.
           localizedStringEvent.StringReference = originalLocalizedString;
    
           // Assign a new Table and Entry. This will trigger an update.
           localizedStringEvent.StringReference.SetReference(tableName, keyId);
    
           // We could do this if we only wanted to change the entry but use the same table
           // localizedStringEvent.StringReference.TableEntryReference = keyId;
       }
    
       if (GUILayout.Button("Increase Age"))
       {
           characterInfo.age++;
    
           // Force the string to refresh
           localizedStringEvent.RefreshString();
       }
    
       if (GUILayout.Button("Decrease Age"))
       {
           characterInfo.age--;
    
           // Force the string to refresh
           localizedStringEvent.RefreshString();
       }
    }
    }

    Example of String Table Contents

    Example of String Table Contents

    Example results in Game

    Example results in Game

    Properties

    OnUpdateString

    Event that will be sent when the localized string is available.

    Declaration
    public UnityEventString OnUpdateString { get; set; }
    Property Value
    Type Description
    UnityEventString

    StringReference

    References the StringTable and StringTableEntry of the localized string.

    Declaration
    public LocalizedString StringReference { get; set; }
    Property Value
    Type Description
    LocalizedString

    Methods

    RefreshString()

    Forces the string to be regenerated, such as when the string formatting argument values have changed.

    Declaration
    public void RefreshString()

    SetEntry(String)

    Changes the TableEntry value of a LocalizeString.

    Declaration
    public void SetEntry(string entryName)
    Parameters
    Type Name Description
    String entryName

    A reference to the entry in the table that will be set to StringReference of a LocalizeString

    SetTable(String)

    Changes the TableReference value of a LocalizeString.

    Declaration
    public void SetTable(string tableReference)
    Parameters
    Type Name Description
    String tableReference

    A reference to the table that will be set to StringReference of a LocalizeString

    UpdateString(String)

    Invokes the OnUpdateString event.

    Declaration
    protected virtual void UpdateString(string value)
    Parameters
    Type Name Description
    String value

    Did you find this page useful? Please give it a rating:

    Thanks for rating this page!

    Report a problem on this page

    What kind of problem would you like to report?

    • This page needs code samples
    • Code samples do not work
    • Information is missing
    • Information is incorrect
    • Information is unclear or confusing
    • There is a spelling/grammar error on this page
    • Something else

    Thanks for letting us know! This page has been marked for review based on your feedback.

    If you have time, you can provide more information to help us fix the problem faster.

    Provide more information

    You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:

    You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:

    You've told us there is information missing from this page. Please tell us more about what's missing:

    You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:

    You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:

    You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:

    You've told us this page has a problem. Please tell us more about what's wrong:

    Thank you for helping to make the Unity documentation better!

    Your feedback has been submitted as a ticket for our documentation team to review.

    We are not able to reply to every ticket submitted.

    In This Article
    • Properties
      • OnUpdateString
      • StringReference
    • Methods
      • RefreshString()
      • SetEntry(String)
      • SetTable(String)
      • UpdateString(String)
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023