Reference API Roblox

Engine API

Website

Related

Reference API Roblox

Translator

The role of a Translator is to manufacture/return strings localized for the viewing player.

This class is not replicated. Its interface does not cross the network boundary.
This class is not creatable. Instances of this class cannot be created with Instance.new.
Tags: [NotCreatable, NotReplicated]

Member index 4

HistoryMember
553LocaleId: string
462FormatByKey(key: string, args: Variant): string
462RobloxOnlyTranslate(context: Instance, text: string): string
462Translate(context: Instance, text: string): string
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Description

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.

History 11

Members 4

FormatByKey

Parameters (2)
keystring
argsVariant
Returns (1)
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 LocalizationTables available to this Translator include 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 Localizing with Scripting for more details and usage examples of this function.

History 2

LocaleId

TypeDefault
string

The Roblox locale of the output translated strings from this table, for example "en-us" or "es-es." Defaults to "en-us".

This property is not replicated. Its interface does not cross the network boundary.
This property is read-only. Its value can be read, but it cannot be modified.

History 4

Tags: [ReadOnly, NotReplicated]

RobloxOnlyTranslate

Parameters (2)
contextInstance
textstring
Returns (1)
string

History 2

Translate

Parameters (2)
contextInstance
textstring
Returns (1)
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 Localizing 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:

ABCDE
KeyContextSourceExamplees
ScreenPantalla
ScreenMosquitero

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:

ABCDE
KeyContextSourceExamplees
workspace.ComputerScreen.SurfaceGui.TextLabelScreenPantalla
ScreenMosquitero

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
local LocalizationService = game:GetService("LocalizationService")

local success, translator = pcall(function()
	return LocalizationService:GetTranslatorForPlayerAsync(game.Players.LocalPlayer)
end)

if success then
	local trans = translator:Translate(workspace.ComputerScreen.SurfaceGui.TextLabel, "Screen")
	print(trans)
else
	warn("Cannot load translator for player!")
end

History 2

Settings