-- This is meant for translating user game text that appears under CoreGui.
-- It uses Player.LocaleId and the LocalizationTables under LocalizationService.
-- This includes team names, score names, tool names, and notification toasts.
-- DO NOT USE THIS TO TRANSLATE ROBLOX TEXT IN ROBLOX GUIS!!!
-- Text from Roblox in Roblox guis should use LocalizationService.RobloxLocaleId
-- and the CoreScriptLocalization table, NOT user tables with the game locale ID.


function GameTranslator:TranslateGameText(context, text)
	if CoreScriptTranslateGameText then
		local translator = getTranslator()
		if translator then
			return translator:RobloxOnlyTranslate(context, text)
		else
			return text
		end
	else
		return text
	end
end

local function retranslateAll()
	for element, info in pairs(registryInfoMap) do
		element.Text = GameTranslator:TranslateGameText(info.context, info.text)
	end
end

if CoreScriptTranslateGameText then
	LocalizationService.AutoTranslateWillRun:Connect(retranslateAll)
end

function GameTranslator:TranslateAndRegister(element, context, text)
	if CoreScriptTranslateGameText then
		element.Text = self:TranslateGameText(context, text)
		registerGui(element, context, text)
	end

	return text
end

return GameTranslator
