function JSONTranslator.FormatByKey(A,M,B)assert(A~=JSONTranslator,"\067\111\110\115\116\114\117\099\116 \097 \110\101\119 \118\101\114\115\105\111\110 \111\102 \116\104\105\115 \099\108\097\115\115 \116\111 \117\115\101 \105\116")assert(type(M)=="\115\116\114\105\110\103","\075\101\121 \109\117\115\116 \098\101 \097 \115\116\114\105\110\103")if not RunService:IsRunning()then return A:_formatByKeyTestMode(M,B)end local d=A:_getClientTranslatorOrError()local Q local i,u=pcall(function()Q=d:FormatByKey(M,B)end)if i and not u then return Q end if u then warn(u)else warn("\070\097\105\108\101\100 \116\111 \108\111\099\097\108\105\122\101 \'"..(M.."\'"))end if d.LocaleId~=A._englishTranslator.LocaleId then i,u=pcall(function()Q=A._englishTranslator:FormatByKey(M,B)end)if i and not u then return Q end end return M end function JSONTranslator._getClientTranslatorOrError(M)assert(M._promiseTranslator,"\067\108\105\101\110\116\084\114\097\110\115\108\097\116\111\114 \105\115 \110\111\116 \105\110\105\116\105\097\108\105\122\101\100")if M._promiseTranslator:IsFulfilled()then return assert(M._promiseTranslator:Wait(),"\070\097\105\108\101\100 \116\111 \103\101\116 \116\114\097\110\115\108\097\116\111\114")else error("\084\114\097\110\115\108\097\116\111\114 \105\115 \110\111\116 \121\101\116 \097\099\113\117\105\114\101\100 \121\101\116")return nil end end function JSONTranslator._formatByKeyTestMode(A,M,B)local d=A._localizationTable:GetTranslator("\101\110")local Q local i,u=pcall(function()Q=d:FormatByKey(M,B)end)if i and not u then return Q end for A,d in pairs(A._fallbacks)do local Q=d:FormatByKey(M,B)if Q then return Q end end if u then warn(u)else warn("\070\097\105\108\101\100 \116\111 \108\111\099\097\108\105\122\101 \'"..(M.."\'"))end return M end
--[=[
	Formats or errors if the cloud translations are not loaded.
	@param key string
	@param args table?
	@return string
]=]
function JSONTranslator:FormatByKey(key, args)
	assert(self ~= JSONTranslator, "Construct a new version of this class to use it")
	assert(type(key) == "string", "Key must be a string")

	if not RunService:IsRunning() then
		return self:_formatByKeyTestMode(key, args)
	end

	local clientTranslator = self:_getClientTranslatorOrError()

	local result
	local ok, err = pcall(function()
		result = clientTranslator:FormatByKey(key, args)
	end)

	if ok and not err then
		return result
	end

	if err then
		warn(err)
	else
		warn("Failed to localize '" .. key .. "'")
	end

	-- Fallback to English
	if clientTranslator.LocaleId ~= self._englishTranslator.LocaleId then
		-- Ignore results as we know this may error
		ok, err = pcall(function()
			result = self._englishTranslator:FormatByKey(key, args)
		end)

		if ok and not err then
			return result
		end
	end

	return key
end

function JSONTranslator:_getClientTranslatorOrError()
	assert(self._promiseTranslator, "ClientTranslator is not initialized")

	if self._promiseTranslator:IsFulfilled() then
		return assert(self._promiseTranslator:Wait(), "Failed to get translator")
	else
		error("Translator is not yet acquired yet")
		return nil
	end
end

function JSONTranslator:_formatByKeyTestMode(key, args)
	-- Can't read LocalizationService.ForcePlayModeRobloxLocaleId :(
	local translator = self._localizationTable:GetTranslator("en")
	local result
	local ok, err = pcall(function()
		result = translator:FormatByKey(key, args)
	end)

	if ok and not err then
		return result
	end

	for _, fallback in pairs(self._fallbacks) do
		local value = fallback:FormatByKey(key, args)
		if value then
			return value
		end
	end

	if err then
		warn(err)
	else
		warn("Failed to localize '" .. key .. "'")
	end

	return key
end
