Translator

Translator : Instance

Overview

Translator is a translator object corresponding to a specific locale. It converts entries registered in cloud translation table into that locale and returns the results.

It cannot be created directly and can only be obtained through LocalizationService:GetTranslatorForLocaleAsync() or LocalizationService:GetTranslatorForPlayerAsync(). For the same locale, a cached instance is reused.

Use Translate() to look up entries by source string, and use FormatByKey() to use an explicitly specified key and format parameters.

Properties

LocaleId

string

A read-only property that returns the locale ID applied to translated strings, formatted like en-us. The default is en-us.

When a Translator is obtained via LocalizationService:GetTranslatorForLocaleAsync() or LocalizationService:GetTranslatorForPlayerAsync(), if the requested locale is unsupported, this value reflects the fallback to English (en). Prefix-based similarity matching (e.g., en-us β†’ en) is also reflected in this value.

Code Samples

local LocalizationService = game:GetService("LocalizationService")
local translator = LocalizationService:GetTranslatorForLocaleAsync("pt-br")

print(translator.LocaleId) -- "pt-br"

Methods

FormatByKey

Returns a localized text string from a cloud translation table by the given key, based on the Translator's locale.

Format parameters in the source text can be filled in by passing them through args, which should be specified as a key-value table.

The supported argument data types are:

  • number

  • string

  • bool

  • Instance (its name is used)

  • CFrame

  • Vector3

  • Vector2

  • Color3

  • BrickColor

  • MenuItem

An error is raised if the number or names of the provided args do not match the formatting tokens in the original Source, or if the key is valid but the translated text for the locale is empty.

Parameters

string Key

The Key value of the entry to look up and translate.

Value Args

The parameters to fill into the format string. Provided as a number-indexed array or a table of named parameters.

Return

string

The translated and formatted text string.

Code Samples

Translate

Looks up the cloud translation table by the original Source text based on the Translator's locale and returns the localized text string.

Unlike FormatByKey(), which looks up entries by Key, Translate() uses the Source text itself as the lookup key.

For the context argument, pass a game-internal Instance used for context override. If no context override is needed, passing game is recommended. When passing an instance inside PlayerGui, only the path under PlayerGui is used as context.

Even if a context is passed, if there is no entry matching that context, it may fall back to matching by Source alone.

Parameters

Instance Context

The instance to use for context matching. If no override is needed, pass game.

string Source

The Source text to look up and translate.

Return

string

The translated text string.

Code Samples

Events

See also

Localization

Last updated