local _, addonTable = ...

addonTable.localization = addonTable.localization or {
    msg =  {},
    tts =  {},
    chat = {},
}
local localization = addonTable.localization

local locale = GetLocale()
local SpeakText = C_VoiceChat.SpeakText

-- Replica to Localized Text
MerfinLocalize = function(replica)
    local source = localization.msg[locale] or localization.msg['enUS']
    return (source and source[replica]) or replica
end

-- Replica to localized Text and Text to Speech
MerfinPlaySound = function(replica, speed, volume, voiceId)
    local source = localization.tts[locale] or localization.tts['enUS']
    local message = source and source[replica]
    if not message then 
        if locale == 'enUS' then
            message = replica
        else
            return 
        end
    end
    SpeakText(voiceId, message, Enum.VoiceTtsDestination.LocalPlayback, speed, volume)
end

-- Replica to localized Text and Text to Speech
MerfinChatMSG = function(message, chatType, ...)
    local source = localization.tts[locale] or localization.tts['enUS']
    local message = (source and source[message]) or message
    if ... then
        message = string.format(message, ...)
    end
    SendChatMessage(message, chatType)
end