Class LocalizedStringTable | Localization | 0.8.1-preview
docs.unity.cn
    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 will fetch the table on demand or provide a callback whenever the table has finished loading, such as when the selected locale was changed.

    Inheritance
    Object
    LocalizedTable<StringTable, StringTableEntry>
    LocalizedStringTable
    Inherited Members
    LocalizedTable<StringTable, StringTableEntry>.Database
    LocalizedTable<StringTable, StringTableEntry>.CurrentLoadingOperation
    LocalizedTable<StringTable, StringTableEntry>.TableReference
    LocalizedTable<StringTable, StringTableEntry>.IsEmpty
    LocalizedTable<StringTable, StringTableEntry>.TableChanged
    LocalizedTable<StringTable, StringTableEntry>.ForceUpdate()
    LocalizedTable<StringTable, StringTableEntry>.GetTable()
    LocalizedTable<StringTable, StringTableEntry>.ToString()
    Namespace: UnityEngine.Localization
    Syntax
    [Serializable]
    public class LocalizedStringTable : LocalizedTable<StringTable, StringTableEntry>
    Examples

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

    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.RegisterChangeHandler(LoadStrings);
        }
    
        void OnDisable()
        {
            m_StringTable.ClearChangeHandler();
        }
    
        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);
            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);
        }
    }

    Properties

    Database

    Declaration
    protected override LocalizedDatabase<StringTable, StringTableEntry> Database { get; }
    Property Value
    Type Description
    LocalizedDatabase<StringTable, StringTableEntry>
    Overrides
    UnityEngine.Localization.LocalizedTable<UnityEngine.Localization.Tables.StringTable, UnityEngine.Localization.Tables.StringTableEntry>.Database
    Back to top Copyright © 2020 Unity Technologies
    Generated by DocFX
    on Wednesday, August 19, 2020