local a=(require(script.Parent.loader)).load(script)local x=game:GetService("\076\111\099\097\108\105\122\097\116\105\111\110\083\101\114\118\105\099\101")local B=game:GetService("\082\117\110\083\101\114\118\105\099\101")local Z=a("\080\114\111\109\105\115\101")local q="\080\117\098\108\105\115\104\105\110\103 \116\104\101 \103\097\109\101 \105\115 \114\101\113\117\105\114\101\100 \116\111 \117\115\101 \071\101\116\084\114\097\110\115\108\097\116\111\114\070\111\114\080\108\097\121\101\114\065\115\121\110\099 \065\080\073\046"local f={}function f.promiseTranslator(a)local f=Z.spawn(function(B,Z)local q=nil local f,G=pcall(function()q=x:GetTranslatorForPlayerAsync(a)end)if not f then Z(G or"\070\097\105\108\101\100 \116\111 \071\101\116\084\114\097\110\115\108\097\116\111\114\070\111\114\080\108\097\121\101\114\065\115\121\110\099")return end if q then assert(typeof(q)=="\073\110\115\116\097\110\099\101","\066\097\100 \116\114\097\110\115\108\097\116\111\114")B(q)return end Z("\084\114\097\110\115\108\097\116\111\114 \119\097\115 \110\111\116 \114\101\116\117\114\110\101\100")return end)local G=20 if B:IsStudio()then G=.5 end task.delay(G,function()if not f:IsPending()then return end f:Reject(("\071\101\116\084\114\097\110\115\108\097\116\111\114\070\111\114\080\108\097\121\101\114\065\115\121\110\099 \105\115 \115\116\105\108\108 \112\101\110\100\105\110\103 \097\102\116\101\114 \037\102\044 \117\115\105\110\103 \108\111\099\097\108 \116\097\098\108\101"):format(G))end)return f:Catch(function(B)if B~=q then warn(("\091\076\111\099\097\108\105\122\097\116\105\111\110\083\101\114\118\105\099\101\085\116\105\108\115\046\112\114\111\109\105\115\101\084\114\097\110\115\108\097\116\111\114\093 - \037\115"):format(tostring(B)))end local Z=x:GetTranslatorForPlayer(a)return Z end)end return f


local require = require(script.Parent.loader).load(script)

local LocalizationService = game:GetService("LocalizationService")
local RunService = game:GetService("RunService")

local Promise = require("Promise")
local ERROR_PUBLISH_REQUIRED = "Publishing the game is required to use GetTranslatorForPlayerAsync API."

local LocalizationServiceUtils = {}

function LocalizationServiceUtils.promiseTranslator(player)
	local asyncTranslatorPromise = Promise.spawn(function(resolve, reject)
		local translator = nil
		local ok, err = pcall(function()
			translator = LocalizationService:GetTranslatorForPlayerAsync(player)
		end)

		if not ok then
			reject(err or "Failed to GetTranslatorForPlayerAsync")
			return
		end

		if translator then
			assert(typeof(translator) == "Instance", "Bad translator")
			resolve(translator)
			return
		end

		reject("Translator was not returned")
		return
	end)

	-- Give longer in non-studio mode
	local timeout = 20
	if RunService:IsStudio() then
		timeout = 0.5
	end

	task.delay(timeout, function()
		if not asyncTranslatorPromise:IsPending() then
			return
		end
		asyncTranslatorPromise:Reject(
			("GetTranslatorForPlayerAsync is still pending after %f, using local table")
			:format(timeout))
	end)

	return asyncTranslatorPromise:Catch(function(err)
		if err ~= ERROR_PUBLISH_REQUIRED then
			warn(("[LocalizationServiceUtils.promiseTranslator] - %s"):format(tostring(err)))
		end

		-- Fallback to just local stuff
		local translator = LocalizationService:GetTranslatorForPlayer(player)
		return translator
	end)
end


return LocalizationServiceUtils
