PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetTranslatorForPlayer

This function takes a player as an argument returns cloud localization data for that Player|player's locale has been loaded, and then returns a Translator object which can be used to perform translations for that locale if any are available.

It will only return data for embedded localization tables, and won’t include any data from web-based tables.

See also

  • LocalizationService/GetTranslatorForPlayerAsync, same functionality as this function except that it yields until the translator has been loaded and includes data from web-based tables
  • LocalizationService/GetTranslatorForLocaleAsync, returns a Translator to be used for translations using the locale data loaded

Parameters

Name Type Default Description

The Player that you are getting the Translator for

Returns

Return Type Summary

The Translator instance for the specified locale


Code Samples


Getting and Using a Translator for a Player

This code sample attempts to retrieve a Translator object for the local player. LocalizationService/GetTranslatorForPlayerAsync is wrapped in a pcall because it may error. If it does not error and returns a Translator, it translates and prints “Hello World!” in the player’s language. If the function errors, it prints “GetTranslatorForLocaleAsync failed:“ followed by the error message.

LocalizationService/GetTranslatorForPlayer can also be used if you’d like to get the player’s translator without yielding until the function returns.

local LocalizationService = game:GetService('LocalizationService')

local res, trans= pcall(function()
    return LocalizationService:GetTranslatorForPlayerAsync(game.Players.LocalPlayer)
end)                                                                                                                                                                                            
	
if res then
	local ctx = game.Workspace.Sign.SurfaceGui.Frame.TextLabel
	local res = trans:Translate(ctx, "Hello World!")
	print(res)
else
	print('GetTranslatorForPlayerAsync failed: ' .. trans)
end