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