Class · inherits Instance
LocalizationTable
A LocalizationTable is a database of translations. It contains source strings and translations for various languages.
About LocalizationTable
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
LocalizationServiceautomatic 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 forLocalizationTable.SourceLocaleIdif 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 1
SourceLocaleId
: stringThe locale of source strings.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 11
GetEntries
() → ArrayReturns an array of dictionaries, where each dictionary represents an entry of localization data.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:
GetTranslator
(localeId: string) → InstanceReturns aTranslatorfor entries in this LocalizationTable, in the specified locale.Returns a
Translatorfor entries in this LocalizationTable, in the specified language. The translator will first search in this table and then look in ancestor tables.RemoveEntry
(key: string, source: string, context: string) → ()Removes an entry from the LocalizationTable, using the specifiedkey,source, andcontextto narrow down the specific entry to be removed.Removes an entry from the LocalizationTable, using the specified
key,source, andcontextto narrow down the specific entry to be removed.The entry is identified by the (
key,source,context) triple. Ifkeyis non-empty it alone identifies the entry because keys are unique within the table. Ifkeyis 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.RemoveEntryValueinstead.RemoveEntryValue
(key: string, source: string, context: string, localeId: string) → ()Removes a single language translation from the LocalizationTable, using the providedkey,source,context, andlocaleIdto narrow down the specific entry to be removed.Removes a single language translation from the LocalizationTable, using the provided
key,source,context, andlocaleIdto narrow down the specific entry to be modified.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). Once the entry is found, only the translation forlocaleIdis erased; the entry itself and all other locale translations remain intact. ThelocaleIdis case-insensitive (it is canonicalized internally). If no matching entry exists, or the entry has no translation forlocaleId, 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, useLocalizationTable.RemoveTargetLocale.RemoveTargetLocale
(localeId: string) → ()Removes all translations from the LocalizationTable with the specified localeId.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
localeIdfrom 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, useLocalizationTable.RemoveEntryValueinstead.SetEntries
(entries: Variant) → ()Sets the contents of the LocalizationTable.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.GetEntriesfunction.SetEntryContext
(key: string, source: string, context: string, newContext: string) → ()Sets the Context field of a LocalizationTable entry tonewContext, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.Sets the Context field of a LocalizationTable entry to
newContext, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). If no matching entry exists, a new entry is created with the providedkey,source, andnewContext. 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.GetFullNamepath that the automatic text replacement system uses for disambiguation when multiple entries share the same Source string.SetEntryExample
(key: string, source: string, context: string, example: string) → ()Sets the Example field of a LocalizationTable entry toexample, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.Sets the Example field of a LocalizationTable entry to
example, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). If no matching entry exists, a new entry is created with the providedkey,source, andcontext. The newexamplevalue 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.
SetEntryKey
(key: string, source: string, context: string, newKey: string) → ()Sets the Key field of a LocalizationTable entry tonewKey, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.Sets the Key field of a LocalizationTable entry to
newKey, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). If no matching entry exists, a new entry is created withnewKey, the providedsource, andcontext. The method throws an error ifnewKeywould conflict with an existing entry's key, because keys must be unique within the table. IfnewKeyequals 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.SetEntrySource
(key: string, source: string, context: string, newSource: string) → ()Sets the Source field of a LocalizationTable entry tonewSource, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.Sets the Source field of a LocalizationTable entry to
newSource, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). If no matching entry exists, a new entry is created with the providedkey,newSource, andcontext. The method throws an error if the resulting (key,newSource,context) combination would conflict with an existing entry. IfnewSourceequals 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
LocalizationServiceautomatic 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.SetEntryValue
(key: string, source: string, context: string, localeId: string, text: string) → ()Sets the text of the specified localeId in a LocalizationTable entry, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.Sets the text of the specified
localeIdin a LocalizationTable entry, using the specifiedkey,source, andcontextto narrow down the entry that will have this change applied.The entry is identified by the (
key,source,context) triple (seeLocalizationTable.RemoveEntryfor lookup rules). If no matching entry exists, a new entry is created with the providedkey,source, andcontext— this throws an error if bothkeyandsourceare empty. ThelocaleIdis case-insensitive (it is canonicalized internally).If
textis non-empty the translation is stored (or replaced) forlocaleIdon that entry. The text must be a valid format string (parameters like{1:translate}must be well-formed or the call throws). Iftextis an empty string the translation forlocaleIdis removed from the entry, equivalent to callingLocalizationTable.RemoveEntryValue.To set multiple entries at once, use
LocalizationTable.SetEntries.
LocalizationTable also has every member of Instance. Deprecated and Roblox-only members are hidden.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.