docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class LocalizedStringTable

    Provides runtime access to a StringTable for the current selected Locale. When accessing multiple localized strings it may be more convenient to use a LocalizedStringTable instead of multiple LocalizedString. This fetches the table on demand or provides a callback when the table finishes loading, such as returning when the selected locale was changed.

    Inheritance
    object
    LocalizedTable<StringTable, StringTableEntry>
    LocalizedStringTable
    Implements
    ISerializationCallbackReceiver
    Inherited Members
    LocalizedTable<StringTable, StringTableEntry>.m_CurrentTable
    LocalizedTable<StringTable, StringTableEntry>.Database
    LocalizedTable<StringTable, StringTableEntry>.CurrentLoadingOperationHandle
    LocalizedTable<StringTable, StringTableEntry>.TableReference
    LocalizedTable<StringTable, StringTableEntry>.IsEmpty
    LocalizedTable<StringTable, StringTableEntry>.TableChanged
    LocalizedTable<StringTable, StringTableEntry>.GetTableAsync()
    LocalizedTable<StringTable, StringTableEntry>.GetTable()
    LocalizedTable<StringTable, StringTableEntry>.ForceUpdate()
    LocalizedTable<StringTable, StringTableEntry>.CurrentLoadingOperation
    Namespace: UnityEngine.Localization
    Assembly: Unity.Localization.dll
    Syntax
    [Serializable]
    public class LocalizedStringTable : LocalizedTable<StringTable, StringTableEntry>, ISerializationCallbackReceiver
    Examples

    This example shows how a StringTable can be used directly in order to get translated strings for multiple entries.

    using UnityEngine;
    using UnityEngine.Localization;
    using UnityEngine.Localization.Metadata;
    using UnityEngine.Localization.Settings;
    using UnityEngine.Localization.Tables;
    
    public class LocalizedStringTableExample : MonoBehaviour
    {
        public LocalizedStringTable m_StringTable = new LocalizedStringTable { TableReference = "My Strings" };
    
        string m_TranslatedStringHello;
        string m_TranslatedStringGoodbye;
        string m_TranslatedStringThisIsATest;
    
        void OnEnable()
        {
            m_StringTable.TableChanged += LoadStrings;
        }
    
        void OnDisable()
        {
            m_StringTable.TableChanged -= LoadStrings;
        }
    
        void LoadStrings(StringTable stringTable)
        {
            m_TranslatedStringHello = GetLocalizedString(stringTable, "Hello");
            m_TranslatedStringGoodbye = GetLocalizedString(stringTable, "Goodbye");
            m_TranslatedStringThisIsATest = GetLocalizedString(stringTable, "This is a test");
        }
    
        static string GetLocalizedString(StringTable table, string entryName)
        {
            var entry = table.GetEntry(entryName);
    
            // We can also extract Metadata here
            var comment = entry.GetMetadata<Comment>();
            if (comment != null)
            {
                Debug.Log($"Found metadata comment for {entryName} - {comment.CommentText}");
            }
    
            return entry.GetLocalizedString(); // We can pass in optional arguments for Smart Format or String.Format here.
        }
    
        void OnGUI()
        {
            if (!LocalizationSettings.InitializationOperation.IsDone)
            {
                GUILayout.Label("Initializing Localization");
                return;
            }
    
            GUILayout.Label(m_TranslatedStringThisIsATest);
            GUILayout.Label(m_TranslatedStringHello);
            GUILayout.Label(m_TranslatedStringGoodbye);
        }
    }

    Constructors

    Name Description
    LocalizedStringTable()

    Initializes and returns an empty instance of a LocalizedStringTable.

    LocalizedStringTable(TableReference)

    Initializes and returns an instance of a LocalizedStringTable.

    Properties

    Name Description
    Database

    The database to request the table from.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)