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.
Inherited Members
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 |
Properties
Database
The database to request the table from.
Declaration
protected override LocalizedDatabase<StringTable, StringTableEntry> Database { get; }
Property Value
Type | Description |
---|---|
LocalizedDatabase<StringTable, StringTableEntry> |