Engine

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

Code Samples

LocalizationTable

local LocalizationService = game:GetService("LocalizationService")
local HttpService = game:GetService("HttpService")
local function createLocalizationTable(contents)
local localTable = Instance.new("LocalizationTable")
localTable.DevelopmentLanguage = LocalizationService.SystemLocaleId
localTable.Contents = HttpService:JSONEncode(contents)
return localTable
end
local helloWorldTable = createLocalizationTable({
[1] = {
key = "Hello_World", -- The 'expressionKey' to be used with GetString
values = { -- A dictionary of keys corresponding to IETF language tags, and their translations.
["ru"] = " !", -- Russian
["fr"] = "Bonjour le monde!", -- French
["de"] = "Hallo Welt!", -- German
["en-US"] = "Hello world!", -- English
["it"] = "Ciao mondo!", -- Italian
["pt-BR"] = "Ol Mundo!", -- Portuguese
["ja"] = "", -- Japanese
["es"] = "Hola Mundo!", -- Spanish
},
},
})
print(helloWorldTable:GetString("en-US", "Hello_World"))

Summary

Properties

Methods

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

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

  • Removes all translations from the LocalizationTable with the specified localeId.

  • 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

read parallel

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

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
KeystringA lookup key for this specific entry in the LocalizationTable.
SourcestringThe string used to format the localized string. Used as a lookup if a key is not provided.
ContextstringAn Instance:GetFullName() path to the object that was used to generate the LocalizationTable. Used as a lookup if a key is not provided.
ExamplestringThe string used to format the localization. Optional.
ValuesDictionaryA 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

local LocalizationService = game:GetService("LocalizationService")
local localizationTable = LocalizationService:FindFirstChild("LocalizationTable")
local entries = {
{
["Key"] = "0001",
["Source"] = "en-us",
["Values"] = {
["0001"] = "Hello Muddah, hello Fadduh.",
["0002"] = "Here I am at Camp Granada.",
["0003"] = "Camp is very entertaining.",
["0004"] = "And they say we'll have some fun if it stops raining.",
},
},
}
localizationTable:SetEntries(entries)
local get_results = localizationTable:GetEntries()
for _index, dict in pairs(get_results) do
for _key, value in pairs(dict["Values"]) do -- Loop through every key, value pair in the dictionary to print our strings
print(value)
end
end

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

Events