docs.unity3d.com
    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
    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>.GetTableAsync()
    LocalizedTable<StringTable, StringTableEntry>.GetTable()
    LocalizedTable<StringTable, StringTableEntry>.ForceUpdate()
    Namespace: UnityEngine.Localization
    Syntax
    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.

    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

    LocalizedStringTable()

    Initializes and returns an empty instance of a LocalizedStringTable.

    Declaration
    public LocalizedStringTable()

    LocalizedStringTable(TableReference)

    Initializes and returns an instance of a LocalizedStringTable.

    Declaration
    public LocalizedStringTable(TableReference tableReference)
    Parameters
    Type Name Description
    TableReference tableReference

    Reference to the String Table Collection. This can either be the name of the collection as a string or the Collection Guid as a System.Guid.

    Properties

    Database

    The database to request the table from.

    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
    Terms of use
    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