Skip to content

Locale

System · Locale · server and client scripts

Locale gets and sets the place's language, loads in-memory place translations, and formats translated strings. On the server Get and System return "en" and Translate returns the key unchanged.

A language tag is a BCP-47 language code with optional script and region, such as "pt-BR" or "zh-Hans". Lookups try the full tag, drop trailing subtags one by one, and fall back to English.

Get

Function
Get() -> string

Get returns the active BCP-47 language tag for the place, "en" until changed.

Example

-- Client script.
local lang = Locale.Get()
if lang == "ja" or string.sub(lang, 1, 2) == "zh" then
    print("use a CJK font")
end

System

Function
System() -> string

System returns the player's platform BCP-47 language tag before any place override.

Example

-- Client script.
print(Locale.System())

Set

Function
Set(tag: string) -> ()

Set switches the active language tag for this session and fires Changed when the tag changes.

Example

-- Client script.
Locale.Set("pt-BR")

AddTranslations

Function
AddTranslations(translations: {[string]: {[string]: string}}) -> ()

AddTranslations registers in-memory place translations keyed by BCP-47 locale tag and message key.

Example

-- Client script.
Locale.AddTranslations({
    ["pt-BR"] = {
        ["Welcome, {name}!"] = "Bem-vindo, {name}!",
    },
})

Translate

Function
Translate(key: string, params: {[string]: string | number}?) -> string

Translate returns the translation of key in the active language, substituting brace placeholders from optional params, or the key itself when no translation matches.

Example

-- Client script.
local line = Locale.Translate("Welcome, {name}!", { name = "Ana" })
print(line)

Changed

EventRead only
Changed: Signal<(tag: string) -> ()>

Changed fires with the new BCP-47 tag when the active place locale changes.

Example

-- Client script.
Locale.Changed:Connect(function(tag: string)
    print("locale changed to " .. tag)
end)