SharedTableData
The shared key table for a localization table collection: the set of string keys and their stable ids that every per-locale table in the collection uses.
Read time 5 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: ScriptableObject
- Implements: ISerializationCallbackReceiver
[HelpURL("localization/localization-tables")]public sealed class SharedTableData : ScriptableObject, ISerializationCallbackReceiver
Remarks
Each key maps to a stable id that never changes for the life of the key, so renaming a key keeps its translations intact. Ids come from the SharedTableData.KeyGenerator, a DistributedUIDGenerator by default, so they are non-sequential and an id of means "no key". Every per-locale ResourceTable in the collection stores its values against these ids. Add and look up keys with SharedTableData.AddKey, SharedTableData.GetId, and SharedTableData.GetKey, and rename in place with SharedTableData.RenameKey. This type derives from ScriptableObject, so create an instance with ScriptableObject factory methods rather than the operator.
long0newAdditional Resources: SharedTableData.SharedTableEntry, SharedEntryFlags, IKeyGenerator, ResourceTable
Create shared data, add a key, and resolve between key text and id.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class SharedTableDataOverviewExample { public void Run() { var sharedData = ScriptableObject.CreateInstance<SharedTableData>(); sharedData.TableCollectionName = "UI Text"; SharedTableData.SharedTableEntry entry = sharedData.AddKey("GREETING"); long id = entry.Id; Debug.Log(sharedData.GetId("GREETING")); // the same id Debug.Log(sharedData.GetKey(id)); // GREETING } }}
Properties
Property | Description |
|---|---|
| Entries | The keys in this shared data, in their current order. |
| KeyGenerator | The generator that assigns stable ids to new keys. |
| Metadata | Collection-level metadata shared across all locale tables. |
| TableCollectionName | The name of the table collection this shared data belongs to. |
| TableCollectionNameGuid | The asset guid of the table collection. |
Methods
Method | Description |
|---|---|
| AddKey | Adds a key and returns its entry. |
| Clear | Removes every key from the shared data. |
| GetEntry | Returns the entry for a stable id. |
| GetId | Returns the stable id for a key. |
| GetKey | Returns the key text for a stable id. |
| IsSmart | Returns whether a key is marked as a Smart String. |
| RemoveKey | Removes a key from the shared data. |
| RenameKey | Renames a key while keeping its id. |
| SetKeyOrder | Reorders the keys to match a given sequence of ids. |
Classes
Class | Description |
|---|---|
| SharedTableData.SharedTableEntry | A single key in the shared data, pairing the key text with its stable id. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |