LocalizationService:GetTranslatorForPlayerAsync
This function takes a player as an argument and yields until the cloud LocalizationTable for that player's locale has been loaded, if available. It then returns a Translator object which can be used to perform translations for that locale if any are available. The entries used for localization are the entries provided by the LocalizationTable hierarchy under LocalizationService as well as the cloud table (if available). This will be the same set of entries returned by LocalizationService:GetTableEntries(nil).
This function can error and thus should be wrapped in a pcall().
See also:
- LocalizationService:GetTranslatorForPlayer(), same functionality as this function except that it does not yield and does not wait until the cloud LocalizationTable for the player's locale has been loaded. This function is deprecated and should not be used in new work.
- LocalizationService:GetTranslatorForLocaleAsync(), returns a Translator to be used for translations using the provided locale.
Parameters
The Player that you are getting the Translator for.
Returns
The Translator instance for the specified locale.
Code Samples
Getting and Using a Translator for a Player
local LocalizationService = game:GetService("LocalizationService")
local Players = game:GetService("Players")
local textLabel = script.Parent
local success, translator = pcall(function()
return LocalizationService:GetTranslatorForPlayerAsync(Players.LocalPlayer)
end)
if success then
local result = translator:Translate(textLabel, "Hello World!")
print(result)
else
print("GetTranslatorForPlayerAsync failed: " .. translator)
end