docs.unity3d.com
    目次を表示する/隠す

    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>.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
    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.

    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
    トップに戻る
    Copyright © 2023 Unity Technologies — 商標と利用規約
    • 法律関連
    • プライバシーポリシー
    • クッキー
    • 私の個人情報を販売または共有しない
    • Your Privacy Choices (Cookie Settings)