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 function createLocalizationTable(entries)
local localTable = Instance.new("LocalizationTable")
localTable.DevelopmentLanguage = LocalizationService.SystemLocaleId
localTable:SetEntries(entries)
return localTable
end
local entries = {
{
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
},
},
}
local helloWorldTable = createLocalizationTable(entries)
print(helloWorldTable:GetString("en-US", "Hello_World"))

Summary

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):()

    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):()

    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):()

    Removes all translations from the LocalizationTable with the specified localeId.

  • SetEntries(entries : Variant):()

    Sets the contents of the LocalizationTable.

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

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

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

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

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

Properties

SourceLocaleId

Read Parallel

Methods

GetEntries


Returns

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

Parameters

localeId: string

Returns

RemoveEntry

()

Parameters

key: string
source: string
context: string

Returns

()

RemoveEntryValue

()

Parameters

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

Returns

()

RemoveTargetLocale

()

Parameters

localeId: string

Returns

()

SetEntries

()

Parameters

entries: Variant

Returns

()

SetEntryContext

()

Parameters

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

Returns

()

SetEntryExample

()

Parameters

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

Returns

()

SetEntryKey

()

Parameters

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

Returns

()

SetEntrySource

()

Parameters

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

Returns

()

SetEntryValue

()

Parameters

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

Returns

()

Events