Roblox UtilitiesDevlHub Roblox Documentation

Class

LocalizationTable

Inherits
Instance › Object
Memory category
Instances

A LocalizationTable is a database of translations. It contains source strings and translations for various languages.

A LocalizationTable is a database of translations. It contains source strings and translations for various languages. It is used with the Translator and LocalizationService auto-translator system to control text translations in the game. LocalizationTables are designed to be treated as resources, like a texture or a script. They are not optimized to be modified at runtime. Changing the contents of a table will cause the entire contents of the table to be replicated to all players.

LocalizationTable Entries#

Each LocalizationTable contains a set of entries. Each entry contains the translations of the text, along with some special fields:

  • Key is an optional unique key for fast hash lookups in code. If it is non-empty it must be unique in the table.
  • Source is the original text in the source language that will be used by the LocalizationService automatic text replacement system to match GUI text and render a translation instead. The Source field can be filled by the text capture tools, or can be set manually. For key-based lookups the Source value can be used as a translation for LocalizationTable.SourceLocaleId if the entry doesn't have a translation for that locale. If Source is empty then the entry will not be used by the automatic replacement system.
  • Context is the full Instance name for the object that the text appeared on. Context is used for disambiguation by the automatic text replacement system. When multiple matches for the Source are found, the system will pick the best match by matching backwards from the end of the Context string. There are other more robust ways to handle disambiguation available as well, like using multiple tables with GuiBase2d.RootLocalizationTable.
  • Example is whatever you want it to be. If the text capture tool guessed some parameters for a string the Example field will contain an example of them used in context.

All of these fields are optional, but at least either Key or Source must be non-empty. No two entries can have the same Key, Source, and Context.

See Translating Dynamic Content for more information.

Properties 3#

DevelopmentLanguagestringThe default IETF tag to use if the ''languageKey'' parameter is excluded from the LocalizationTable:GetString() method.ReadSafeDeprecatedHiddenNotReplicated
RootInstanceThe object that is being targeted for localization by this table. Localization is applied to it and all of it's descendants.ReadSafeDeprecatedHiddenNotReplicated
SourceLocaleIdstringThe locale of source strings.ReadSafe

DevelopmentLanguage: string#

HiddenNotReplicatedDeprecatedReadSafeDeprecated

Deprecated. This item has been superseded by LocalizationTable.SourceLocaleId which should be used in all new work.

The default IETF tag to use if the ''languageKey'' parameter is excluded from the LocalizationTable:GetString() method.

Root: Instance#

HiddenNotReplicatedDeprecatedReadSafeDeprecated

Deprecated. This item is deprecated. Do not use it for new work.

The object that is being targeted for localization by this table. Localization is applied to it and all of it's descendants.

SourceLocaleId: string#

ReadSafe

The Roblox locale of the input key strings for this table, for example "en-us" or "es-es." This is typically the "development language" of the game. For a Translator that merges multiple LocalizationTable objects, it's the LocaleId of the Default LocalizationTable. Defaults to "en-us".

Methods 16#

GetContentsReturns the contents of the LocalizationTable serialized as a JSON string.Deprecated
GetEntriesReturns an array of dictionaries, where each dictionary represents an entry of localization data.
GetStringReturns a translation based on the specified language and key.Deprecated
GetTranslatorReturns a Translator for entries in this LocalizationTable, in the specified locale.
RemoveEntryRemoves an entry from the LocalizationTable, using the specified key, source, and context to narrow down the specific entry to be removed.
RemoveEntryValueRemoves a single language translation from the LocalizationTable, using the provided key, source, context, and localeId to narrow down the specific entry to be removed.
RemoveKeyDeprecated in favor of LocalizationTable:RemoveEntry().Deprecated
RemoveTargetLocaleRemoves all translations from the LocalizationTable with the specified localeId.
SetContentsSets the contents of the LocalizationTable, via the legacy JSON format.Deprecated
SetEntriesSets the contents of the LocalizationTable.
SetEntrySets the translation text for the targetLocaleId locale on the entry identified by key, creating the entry if it doesn't exist.Deprecated
SetEntryContextSets the Context field of a LocalizationTable entry to newContext, using the specified key, source, and context to narrow down the entry that will have this change applied.
SetEntryExampleSets the Example field of a LocalizationTable entry to example, using the specified key, source, and context to narrow down the entry that will have this change applied.
SetEntryKeySets the Key field of a LocalizationTable entry to newKey, using the specified key, source, and context to narrow down the entry that will have this change applied.
SetEntrySourceSets the Source field of a LocalizationTable entry to newSource, using the specified key, source, and context to narrow down the entry that will have this change applied.
SetEntryValueSets the text of the specified localeId in a LocalizationTable entry, using the specified key, source, and context to narrow down the entry that will have this change applied.

GetContents(): string#

DeprecatedDeprecated

Deprecated. This item has been superseded by LocalizationTable:GetEntries() which should be used in all new work.

Deprecated. Prefer LocalizationTable:GetEntries(), which returns the same data as a structured array of dictionaries. Returns all entries in the LocalizationTable encoded as a JSON-formatted string, the legacy serialized representation of the table's contents. Each entry is an object containing its key, context, examples, and source fields (each omitted when empty) along with a values map of locale IDs to translated strings.

Returns
  • string — The table's entries encoded as a JSON-formatted string.

GetEntries(): Array#

The GetEntries function returns an array of dictionaries contained in a given LocalizationTable, where each dictionary represents an entry of localization data.

To set the entries of a LocalizationTable, you can use LocalizationTable:SetEntries().

Each dictionary in the array contains the following fields:

Index Type Description
Key Library.string A lookup key for this specific entry in the LocalizationTable.
Source Library.string The string used to format the localized string. Used as a lookup if a key is not provided.
Context Library.string An Class.Instance:GetFullName() path to the object that was used to generate the LocalizationTable. Used as a lookup if a key is not provided.
Example Library.string The string used to format the localization. Optional.
Values Dictionary A dictionary of language translations for this localization entry. The keys of this dictionary are locale ids, and the values are strings that are used to apply localization for the language corresponding to the locale id.
Returns
  • Array — An array of dictionaries, where each dictionary represents an entry of localization data.

GetString(targetLocaleId: string, key: string): string#

DeprecatedDeprecated

Deprecated. This item has been superseded by LocalizationTable:GetTranslator() which should be used in all new work.

The GetString function returns a translation based on the specified language and key.

NameTypeDefaultDescription
targetLocaleIdstringSpecified language.
keystringAn optional unique key for fast hash lookups in code. If it is non-empty it must be unique in the table.
Returns
  • string — Translated string.

GetTranslator(localeId: string): Instance#

Returns a Translator for entries in this LocalizationTable, in the specified language. The translator will first search in this table and then look in ancestor tables.

NameTypeDefaultDescription
localeIdstringA Roblox locale identifier (for example, "en-us" or "es-es") specifying the language the returned Translator should target.
Returns

RemoveEntry(key: string, source: string, context: string): ()#

Removes an entry from the LocalizationTable, using the specified key, source, and context to narrow down the specific entry to be removed.

The entry is identified by the (key, source, context) triple. If key is non-empty it alone identifies the entry because keys are unique within the table. If key is empty the entry is matched by the (source, context) pair. When no matching entry exists the call is a silent no-op.

Removing an entry deletes all of its translations and metadata. To remove only a single locale's translation from an entry while keeping the entry itself, use LocalizationTable:RemoveEntryValue() instead.

NameTypeDefaultDescription
keystringThe unique key of the entry to remove. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path used for disambiguation. Used with source to identify the entry when key is empty.
Returns
  • ()

RemoveEntryValue(key: string, source: string, context: string, localeId: string): ()#

Removes a single language translation from the LocalizationTable, using the provided key, source, context, and localeId to narrow down the specific entry to be modified.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). Once the entry is found, only the translation for localeId is erased; the entry itself and all other locale translations remain intact. The localeId is case-insensitive (it is canonicalized internally). If no matching entry exists, or the entry has no translation for localeId, the call is a silent no-op.

To remove the entire entry including all translations, use LocalizationTable:RemoveEntry(). To remove every translation of a given locale across all entries, use LocalizationTable:RemoveTargetLocale().

NameTypeDefaultDescription
keystringThe unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path used for disambiguation. Used with source to identify the entry when key is empty.
localeIdstringThe locale identifier (for example, "fr-fr") whose translation should be removed from the entry.
Returns
  • ()

RemoveKey(key: string): ()#

DeprecatedDeprecated

Deprecated. This item has been superseded by LocalizationTable:RemoveEntry() which should be used in all new work

Deprecated in favor of LocalizationTable:RemoveEntry(). Calling RemoveKey is the same as making the following call to RemoveEntry:

NameTypeDefaultDescription
keystringThe unique key of the entry to remove.
Returns
  • ()

RemoveTargetLocale(localeId: string): ()#

Removes all translations from the LocalizationTable with the specified localeId.

This is a bulk operation that iterates every entry in the table and erases the translation for localeId from each one. Entries themselves are not removed even if they have no remaining translations after this call. To remove a single translation from one specific entry, use LocalizationTable:RemoveEntryValue() instead.

NameTypeDefaultDescription
localeIdstringA Roblox locale identifier (for example, "fr-fr") specifying which language's translations to remove from all entries.
Returns
  • ()

SetContents(contents: string): ()#

DeprecatedDeprecated

Deprecated. This item has been superseded by LocalizationTable:SetEntries() which should be used in all new work

The SetContents function sets the contents of the LocalizationTable, via the legacy JSON format.

NameTypeDefaultDescription
contentsstringA JSON-formatted string encoding the table's entries, in the same format returned by LocalizationTable:GetContents().
Returns
  • ()

SetEntries(entries: Variant): ()#

Sets the contents of the LocalizationTable.

The entries parameter should be an array of dictionaries in the same format as the one returned from the LocalizationTable:GetEntries() function.

NameTypeDefaultDescription
entriesVariantAn array of dictionaries in the same format returned by LocalizationTable:GetEntries(), each containing Key, Source, Context, Example, and Values fields.
Returns
  • ()

SetEntry(key: string, targetLocaleId: string, text: string): ()#

DeprecatedDeprecated

Deprecated. This item has been superseded by LocalizationTable:SetEntries() which should be used in all new work.

Deprecated. Prefer LocalizationTable:SetEntryValue() for matching an entry by key, source, and context, or LocalizationTable:SetEntries() to set many entries at once. Sets the translation text for the locale targetLocaleId on the LocalizationTable entry identified by key, creating a new entry with an empty source and context if no entry with that key exists. When targetLocaleId matches the table's LocalizationTable.SourceLocaleId, the entry's Source field is also set to text.

NameTypeDefaultDescription
keystringThe unique key identifying the entry. If no entry with this key exists, a new entry is created.
targetLocaleIdstringThe Roblox locale identifier (for example, "en-us" or "fr-fr") for the translation to set.
textstringThe translation text to store for the specified locale.
Returns
  • ()

SetEntryContext(key: string, source: string, context: string, newContext: string): ()#

Sets the Context field of a LocalizationTable entry to newContext, using the specified key, source, and context to narrow down the entry that will have this change applied.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). If no matching entry exists, a new entry is created with the provided key, source, and newContext. The method throws an error if setting the new context would cause the entry to conflict with another existing entry that shares the same key, source, and context combination.

The Context field stores an Instance:GetFullName() path that the automatic text replacement system uses for disambiguation when multiple entries share the same Source string.

NameTypeDefaultDescription
keystringThe unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe current Instance:GetFullName() path of the entry. Used with source to identify the entry when key is empty.
newContextstringThe new context string to assign to the entry.
Returns
  • ()

SetEntryExample(key: string, source: string, context: string, example: string): ()#

Sets the Example field of a LocalizationTable entry to example, using the specified key, source, and context to narrow down the entry that will have this change applied.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). If no matching entry exists, a new entry is created with the provided key, source, and context. The new example value always overwrites any existing example text on the entry.

The Example field is an arbitrary metadata string. The text-capture tools use it to store a sample of parameterized content in context, but developers may store any helpful annotation.

NameTypeDefaultDescription
keystringThe unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path of the entry. Used with source to identify the entry when key is empty.
examplestringThe new example text to assign to the entry, typically a sample of parameterized content in context.
Returns
  • ()

SetEntryKey(key: string, source: string, context: string, newKey: string): ()#

Sets the Key field of a LocalizationTable entry to newKey, using the specified key, source, and context to narrow down the entry that will have this change applied.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). If no matching entry exists, a new entry is created with newKey, the provided source, and context. The method throws an error if newKey would conflict with an existing entry's key, because keys must be unique within the table. If newKey equals the entry's current key the call is a no-op.

The Key field is an optional unique identifier for fast hash lookups via Translator:FormatByKey(). When non-empty it must be unique across the entire table.

NameTypeDefaultDescription
keystringThe current unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path of the entry. Used with source to identify the entry when key is empty.
newKeystringThe new key string to assign to the entry. Must be unique within the table if non-empty.
Returns
  • ()

SetEntrySource(key: string, source: string, context: string, newSource: string): ()#

Sets the Source field of a LocalizationTable entry to newSource, using the specified key, source, and context to narrow down the entry that will have this change applied.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). If no matching entry exists, a new entry is created with the provided key, newSource, and context. The method throws an error if the resulting (key, newSource, context) combination would conflict with an existing entry. If newSource equals the entry's current source the call is a no-op.

The Source field is the original text in the source language used by the LocalizationService automatic text replacement system to match GUI text at runtime. Changing the source also recomputes the internal expression matcher, so parameterized format strings (e.g. {1:translate}) are re-parsed immediately.

NameTypeDefaultDescription
keystringThe unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe current source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path of the entry. Used with source to identify the entry when key is empty.
newSourcestringThe new source text to assign to the entry. Used by the automatic text replacement system for matching GUI text at runtime.
Returns
  • ()

SetEntryValue(key: string, source: string, context: string, localeId: string, text: string): ()#

Sets the text of the specified localeId in a LocalizationTable entry, using the specified key, source, and context to narrow down the entry that will have this change applied.

The entry is identified by the (key, source, context) triple (see LocalizationTable:RemoveEntry() for lookup rules). If no matching entry exists, a new entry is created with the provided key, source, and context — this throws an error if both key and source are empty. The localeId is case-insensitive (it is canonicalized internally).

If text is non-empty the translation is stored (or replaced) for localeId on that entry. The text must be a valid format string (parameters like {1:translate} must be well-formed or the call throws). If text is an empty string the translation for localeId is removed from the entry, equivalent to calling LocalizationTable:RemoveEntryValue().

To set multiple entries at once, use LocalizationTable:SetEntries().

NameTypeDefaultDescription
keystringThe unique key of the entry. If non-empty, identifies the entry by itself.
sourcestringThe source text of the entry. Used with context to identify the entry when key is empty.
contextstringThe Instance:GetFullName() path of the entry. Used with source to identify the entry when key is empty.
localeIdstringThe Roblox locale identifier (for example, "fr-fr") for the translation to set or remove.
textstringThe translation text to store. If empty, the translation for the specified locale is removed from the entry.
Returns
  • ()

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed