@name Google Translator
@persist LanguageFrom:string LanguageTo:string ShowHelp

if (first() | duped()) # ignore this lien
{ # and this line
######## Settings ########
#---- Translate from
# en = english
# de = german
# es = spanish
# fr = french
# etc...
#
# Note: In the most cases it will auto detect the language.
#
# Default: "en"
#
LanguageFrom = "de"
#----

#---- Translate to
# en = english
# de = german
# es = spanish
# fr = french
# etc...
#
# Default: "de"
#
LanguageTo = "en"
#----

#---- Show help on e2 spawn
#
# 1 = on; 0 = off
#
# Default: 1
#
ShowHelp = 1
#----
##########################
}

runOnHTTP(1)
runOnChat(1)

if (first() | duped())
{
    hint("Google Translator activated!",4)
    hint("Made by Pennerlord",6)
    hint("Translate from \""+LanguageFrom+"\" to \""+LanguageTo+"\"",8)
    
    if (ShowHelp)
    {
        printColor(vec(255,150,0),"Commands:")
        printColor(vec(255,150,0),"/langfrom <en/de/es/fr/etc...> - Set the language that will be translated from.")
        printColor(vec(255,150,0),"/langto <en/de/es/fr/etc...> - Set the language that will be translated to.")
    }
}

if (chatClk(owner()))
{
    S = owner():lastSaid():explode(" ")
    
    if (S[1,string] == "/langfrom")
    {
        hideChat(1)
        
        LanguageFrom = S[2,string]
        hint("Set \"Language from\" to: "+S[2,string],5)
    }
    elseif (S[1,string] == "/langto")
    {
        hideChat(1)
        
        LanguageTo = S[2,string]
        hint("Set \"Language to\" to: "+S[2,string],5)
    }
    else
    {
        if (httpCanRequest())
        {
            httpRequest("http://translate.google.com/translate_a/t?client=t&text="+lastSaid():replace(" ","%20")+"&hl="+LanguageTo+"&sl="+LanguageFrom+"&tl="+LanguageTo+"&pc=0")
        }
    }
}

if (chatClk())
{
    if (httpCanRequest())
    {
        httpRequest("http://translate.google.com/translate_a/t?client=t&text="+lastSaid():replace(" ","%20")+"&hl="+LanguageTo+"&sl="+LanguageFrom+"&tl="+LanguageTo+"&pc=0")
    }
}

if (httpClk())
{
    Data = httpData():explode(",")
    Translated = Data[1,string]:right(Data[1,string]:length()-4)
    Translated = Translated:left(Translated:length()-1)
    
    printColor(vec(255,150,0),Translated)
}
