LocalizationTable

Show Deprecated

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

Code Samples

LocalizationTable

1local LocalizationService = game:GetService("LocalizationService")
2local HttpService = game:GetService("HttpService")
3
4local function createLocalizationTable(contents)
5 local localTable = Instance.new("LocalizationTable")
6 localTable.DevelopmentLanguage = LocalizationService.SystemLocaleId
7 localTable.Contents = HttpService:JSONEncode(contents)
8 return localTable
9end
10
11local helloWorldTable = createLocalizationTable({
12 [1] = {
13 key = "Hello_World", -- The 'expressionKey' to be used with GetString
14 values = { -- A dictionary of keys corresponding to IETF language tags, and their translations.
15 ["ru"] = " !", -- Russian
16 ["fr"] = "Bonjour le monde!", -- French
17 ["de"] = "Hallo Welt!", -- German
18 ["en-US"] = "Hello world!", -- English
19 ["it"] = "Ciao mondo!", -- Italian
20 ["pt-BR"] = "Ol Mundo!", -- Portuguese
21 ["ja"] = "", -- Japanese
22 ["es"] = "Hola Mundo!", -- Spanish
23 },
24 },
25})
26
27print(helloWorldTable:GetString("en-US", "Hello_World"))

Summary

Properties

The locale of source strings.

Events

Methods


Returns an array of dictionaries, where each dictionary represents an entry of localization data.

GetTranslator(localeId: string): Instance  

Returns a Translator for entries in this LocalizationTable, in the specified language.

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

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

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

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

RemoveTargetLocale(localeId: string): void  

Removes all translations from the LocalizationTable with the specified localeId.

SetEntries(entries: Variant): void  

Sets the contents of the LocalizationTable.

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

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.

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

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.

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

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.

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

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.

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

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.

Properties

SourceLocaleId

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

Events

Methods

GetEntries

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:

IndexTypeDescription
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`Library.string`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

An array of dictionaries, where each dictionary represents an entry of localization data.

Code Samples

Using a LocalizationTable

1local LocalizationService = game:GetService("LocalizationService")
2
3local localizationTable = LocalizationService:FindFirstChild("LocalizationTable")
4
5local entries = {
6 {
7 ["Key"] = "0001",
8 ["Source"] = "en-us",
9 ["Values"] = {
10 ["0001"] = "Hello Muddah, hello Fadduh.",
11 ["0002"] = "Here I am at Camp Granada.",
12 ["0003"] = "Camp is very entertaining.",
13 ["0004"] = "And they say we'll have some fun if it stops raining.",
14 },
15 },
16}
17
18localizationTable:SetEntries(entries)
19local get_results = localizationTable:GetEntries()
20
21for _index, dict in pairs(get_results) do
22 for _key, value in pairs(dict["Values"]) do -- Loop through every key, value pair in the dictionary to print our strings
23 print(value)
24 end
25end

GetTranslator

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.

Parameters

localeId: string

Returns

RemoveEntry

void

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

Parameters

key: string
source: string
context: string

Returns

void

RemoveEntryValue

void

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

Parameters

key: string
source: string
context: string
localeId: string

Returns

void

RemoveTargetLocale

void

Removes all translations from the LocalizationTable with the specified localeId.

Parameters

localeId: string

Returns

void

SetEntries

void

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.

Parameters

entries: Variant

Returns

void

SetEntryContext

void

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.

Parameters

key: string
source: string
context: string
newContext: string

Returns

void

SetEntryExample

void

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.

Parameters

key: string
source: string
context: string
example: string

Returns

void

SetEntryKey

void

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.

Parameters

key: string
source: string
context: string
newKey: string

Returns

void

SetEntrySource

void

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.

Parameters

key: string
source: string
context: string
newSource: string

Returns

void

SetEntryValue

void

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.

Parameters

key: string
source: string
context: string
localeId: string
text: string

Returns

void

SetIsExemptFromUGCAnalytics

void
Roblox Script Security

Parameters

value: boolean

Returns

void