Class
Translator
NotCreatableNotReplicated
The role of a Translator is to manufacture/return strings localized for the viewing player.
The role of a Translator is to manufacture/return strings localized for the
viewing player. It can be used to retrieve display-ready localized text from a
LocalizationTable. The source of the Translator.LocaleId
property, the set of tables it will search, and the order it will search them
in depends on which method was used to create the Translator instance.
The input for a Translator is the original development language string and a context, where all or part of the context can be used to find a more precise/situational translation for the source string.
The Translator can also be used to manufacture translated strings with inserts (data replacements) which may change order based on the target language.
Properties 1#
LocaleIdstring | The locale of translated strings.ReadSafeReadOnlyNotReplicated |
LocaleId: string#
ReadOnlyNotReplicatedReadSafe
The Roblox locale of the output translated strings from this table, for example "en-us" or "es-es." Defaults to "en-us".
Methods 2#
| FormatByKey | Returns the localized text string in a LocalizationTable based on
its Translator locale, by key. |
| Translate | Returns the localized text string in a LocalizationTable based on
its Translator locale, by source lookup. |
FormatByKey(key: string, args: Variant): string#
Returns the localized text string in a LocalizationTable based on
its Translator locale, by key. The optional args table is used
for filling format parameters in the matching text entry.
Note that this method will throw an error in the following cases:
- If none of the
LocalizationTablesavailable to thisTranslatorinclude a value for the given key. - If the format string for the key uses numbered parameters and args is not an array.
- If the format string uses named parameters and args is not a table of key-value pairs.
- If args is missing values for parameters that are used in the matching format string.
See Localize with scripting for more details and usage examples of this function.
| Name | Type | Default | Description |
|---|---|---|---|
key | string | The Key value to look up and translate. | |
args | Variant | To be provided if the Source text and translations contain format strings. Will be a Luau table of values or key-value pairs, depending on whether the format strings are numbered or named. |
Returns
string— The localized text string associated with the given key, with any format parameters filled in from args.
Translate(context: Instance, text: string): string#
Returns the localized text string in a LocalizationTable based on
its Translator locale. This string will be in the context of the
provided object, given the provided Source text.
See Localize with scripting for more details and usage examples of this function.
Context Overrides#
In some cases, duplicate Source strings may have completely different translations in other languages. For example, the English noun "Screen" can indicate both a computer screen and a window screen, but the Spanish translations are completely different:
| A | B | C | D | E |
| Key | Context | Source | Example | es |
| Screen | Pantalla | |||
| Screen | Mosquitero | |||
In these cases, the first argument to this function — a valid
in-game Instance — can be used as a "tie breaker" when
multiple GUI objects use the same source string. To implement this,
specify the "path" to the Instance you'd like to override as the
Context value of the translation data:
| A | B | C | D | E |
| Key | Context | Source | Example | es |
| workspace.ComputerScreen.SurfaceGui.TextLabel | Screen | Pantalla | ||
| Screen | Mosquitero | |||
Then, when calling this function in a script, pass the same
Instance as the first argument, followed by the Source lookup
text as the second argument:
| Name | Type | Default | Description |
|---|---|---|---|
context | Instance | A valid in-game Instance to use for context override as
outlined above. Note that this argument can be arbitrary, for example
game, if you don't require a context override. | |
text | string | The Source text to look up and translate. |
Returns
string— The translated text.
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild