@name Language Translator - By Moglizorz - Partially Patched by Scorn
@outputs 
@persist Lang:string  #E:entity RD:ranger 
runOnChat(1)
runOnHTTP(1)
#runOnTick(1)
#E = entity():isWeldedTo() ?: entity() 
## HOLOGRAM DESIGNED FOR DETECTING LANGUAGE.
if(first()){Lang="en"
   
    #holoCreate(1,E:toWorld( vec(0,0,0)),vec(5,5,5),E:toWorld( ang(0,0,0)),vec(150,255,150))
    #holoModel(1,"hq_torus")
    #holoCreate(2,E:toWorld( vec(0,0,80)),vec(4,4,7),E:toWorld( ang(0,0,0)),vec(150,255,150))
    #holoModel(2,"hq_tube_thin")
    #holoAlpha(2,50)
    #holoCreate(3,E:toWorld( vec(0,0,80)),vec(5,5,5),E:toWorld( ang(0,0,0)),vec(150,255,150))
    #holoModel(3,"hq_torus")
    }elseif(duped()){reset()}
if((chatClk(owner()))&(lastSaid():sub(1,6)=="!lang ")){
    hideChat(1)
    print("[Hidden] Set language to: "+lastSaid():sub(6))
    Lang=lastSaid():sub(7,lastSaid():length())
}elseif((lastSaid():sub(1,1)=="~")&(chatClk(owner()))){
    hideChat(1)
    print("[Hidden] Translating: "+lastSaid():sub(2))
    httpRequest("http://api.apertium.org/json/translate?q="+httpUrlEncode(lastSaid():sub(2,lastSaid():length()))+"&langpair=en|"+Lang )
}
if((httpClk())&(httpRequestUrl():find("http://api.apertium.org/json/translate?q=")>0)) {
    S=httpData()
    S=httpUrlDecode(S)
    X=S
 #    Z = S
    Y=S
   # Z=S
 #[   Z=Z:sub(Z:find("responseStatus\":")+16)
    Z=Z:sub(1,Z:find("})"))
    Z=Z:replace("&amp;","&"):replace("&quot;","\"") ]#
    Y=Y:sub(Y:find("responseDetails\":")+17)
    Y=Y:sub(1,Y:find(",\"responseStatus"))
    Y=Y:replace("&amp;","&"):replace("&quot;","\"")
    X=X:sub(X:find("\"translatedText\":\"")+18)
    X=X:sub(0,X:find("\"},\"re"))
    X=X:replace("&amp;","&"):replace("&quot;","\"")
    X=X:replace("&quot"," ")
  
    if(Z==200){
        print("[Hidden] Text Translated Successfully")
        print("[Hidden] Translation: "+X)
        concmd("say\""+X+"\"")
    }
    elseif(Z == 200){
        print("[Hidden] Translation Failed: Bad Arguments.")
    }elseif(Z== 451){
        print("[Hidden] Translation Failed: Unsupported Translation Pair.")
    }elseif(Z== 452){
        print("[Hidden] Translation Failed: Unsupported Format.")
    }elseif(Z == 500){
        print("[Hidden] Translation Failed: Critical Error: \""+Y+"\"")
    }elseif(Z == 552){
        print("[Hidden] Translation Failed: Trafic Limit from this IP exceeded.")
    }else{
        print("[Hidden] Translation status unknown: Unknown response code \""+Z+"\"")
        concmd("say\""+X+"\"")
    }
}
#holoPos(1,E:toWorld( vec(0,0,0)))
#holoPos(2,E:toWorld( vec(0,0,40)))
#holoPos(3,E:toWorld( vec(0,0,80)))
#holoAng(1,E:toWorld( ang(0,0,0)))
#holoAng(2,E:toWorld( ang(0,0,0)))
#holoAng(3,E:toWorld( ang(0,0,0)))
#RD = ranger(80,0,0)
#if((chatClk(RD:entity()))&(lastSaid() != "")){
#    print("[Hidden] Detecting language: "+lastSaid())
#    httpRequest("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Detect?Text="+httpUrlEncode(lastSaid())+"\"")
#}
#if((httpClk())&(httpRequestUrl():find("https://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Detect?Text=")>0)) {
#    Y1=httpData()
#    Y1=Y1:replace("&amp;","&"):replace("&quot;","\"")
#    Y1=httpUrlDecode(Y1)
#    print("[Hidden] Language Detected: "+Y1)
#}
#if(RD:entity()){
#Target = RD:entity()
#}else{
#Target = Target
#}

#http://api.datamarket.azure.com/Bing/MicrosoftTranslator/v1/Translate?Text=%27Hello%27&To=%27fr%27&From=%27en%27
#[
!lang to set the language. (eg '!lang fr' for French)
~Text to write in that language. (eg '~Hello, how are you?')
You must set: wire_expression2_concmd 1

af = Afrikaans
sq = Albanian
ar = Arabic
be = Belarusian
bg = Bulgarian
ca = Catalan
zh-CN = Chinese
hr = Croatian
cs = Czech
da = Danish
nl = Dutch
en = English
et = Estonian
tl = Filipino
fi = Finnish
fr = French
gl = Galician
de = German
el = Greek
ht = Haitian Creole
iw = Hebrew
hi = Hindi
hu = Hungarian
is = Icelandic
id = Indonesian
ga = Irish
it = Italian
ja = Japanese
ko = Korean
lv = Latvian
lt = Lithuanian
mk = Macedonian
ms = Malay
mt = Maltese
no = Norwegian
fa = Persian
pl = Polish
pt = Portuguese
pt-PT = Portuguese(Portugal)
ro = Romanian
ru = Russian
sr = Serbian
sk = Slovak
sl = Slovenian
es = Spanish
sw = Swahili
sv = Swedish
th = Thai
tr = Turkish
uk = Ukrainian
vi = Vietnamese
cy = Welsh
yi = Yiddish
]#

K = owner():lastSaid()
if(K:find("'")){
    K:replace("'"," ")
}    
