function serviceHeader(){return new ServiceHeader(28,"Baidu","Baidu Translate is a free online translation service."+Const.NL2+serviceHost()+Const.NL2+"\u00a9 2018 Baidu",Capability.TRANSLATE|Capability.DETECT_LANGUAGE|Capability.LISTEN)}function serviceHost(b,d,e){return b===Capability.LISTEN?"https://tts.baidu.com":"https://fanyi.baidu.com"}
function serviceLink(b,d,e){var g=serviceHost();b&&(d=isLanguage(d)?codeFromLanguage(d):"auto",e=isLanguage(e)?codeFromLanguage(e):"auto",g+=format("/#{0}/{1}/{2}",d,e,encodeGetParam(b)));return g}
SupportedLanguages=[-1,-1,-1,-1,-1,"ara",-1,-1,-1,"bul",-1,"zh","cht",-1,"cs","dan","nl","en","est","fin",-1,"fra",-1,"de","el",-1,-1,-1,"hu",-1,-1,"it",-1,"jp",-1,"kor",-1,-1,-1,-1,-1,-1,-1,"pl","pt","rom","ru",-1,-1,"slo","spa",-1,"swe","th",-1,-1,-1,"vie",-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1];function a(b,d){for(var e=0;e<d.length-2;e+=3){var g=d.charAt(e+2),g="a"<=g?g.charCodeAt(0)-87:Number(g),g="+"===d.charAt(e+1)?b>>>g:b<<g;b="+"===d.charAt(e)?b+g&4294967295:b^g}return b}
function sign(b,d){var e=b.length;30<e&&(b=""+b.substr(0,10)+b.substr(Math.floor(e/2)-5,10)+b.substr(b.length-10));var g=d.split("."),e=Number(g[0])||0,g=Number(g[1])||0,f,c=e;for(f=0;f<b.length;f++){var h=b.charCodeAt(f);128>h?c=a(c+h,"+-a^+6"):(2048>h?c=a(c+(h>>6|192),"+-a^+6"):(55296==(64512&h)&&f+1<b.length&&56320==(64512&b.charCodeAt(f+1))?(h=65536+((1023&h)<<10)+(1023&b.charCodeAt(++f)),c=a(c+(h>>18|240),"+-a^+6"),c=a(c+(h>>12&63|128),"+-a^+6")):c=a(c+(h>>12|224),"+-a^+6"),c=a(c+(h>>6&63|128),
"+-a^+6")),c=a(c+(63&h|128),"+-a^+6"))}c=a(c,"+-3^+b+-f");c^=g;0>c&&(c=(2147483647&c)+2147483648);c%=1E6;return c.toString()+"."+(c^e)}function serviceDetectLanguageRequest(b){b.length>Const.MAX_QUERY_LEN&&(b=b.slice(0,Const.MAX_QUERY_LEN));var d=(Options.BaiduTokens||"||").split("|")[2];b="query="+encodeGetParam((b||"").slice(0,100));d=postHeader()+Const.NL+"Cookie: "+d;return new RequestData(HttpMethod.POST,"/langdetect",b,d)}
function serviceDetectLanguageResponse(b){return(b=parseJSON(b))&&b.lan?languageFromCode(b.lan):UNKNOWN_LANGUAGE}
function serviceTranslateRequest(b,d,e){b=prepareSource(b);b.length>Const.MAX_QUERY_LEN&&(b=b.slice(0,Const.MAX_QUERY_LEN));var g=(Options.BaiduTokens||"||").split("|"),f=g[0],c=g[1],g=g[2];b=format("query={0}&from={1}&to={2}&simple_means_flag=3&sign={3}&token={4}",encodeURIComponent(b).replace(/%20/g,"+"),codeFromLanguage(d),codeFromLanguage(e),sign(b,c),f);d=postHeader()+Const.NL+"Cookie: "+g;return new RequestData(HttpMethod.POST,"/v2transapi",b,d)}
function serviceTranslateResponse(b,d,e,g){var f=parseJSON(d);b="";var c;if(f){if(f.trans_result){e=f.trans_result.data;for(d=0;d<e.length;d++){for(c=0;c<e[d].prefixWrap;c++)b+=Const.NL;b+=e[d].dst+Const.NL}e=languageFromCode(f.trans_result.from);g=languageFromCode(f.trans_result.to)}if(f.dict_result&&f.dict_result.simple_means){var h=f.dict_result.simple_means;b+=Const.NL;if(h&&h.symbols)for(d=0;d<h.symbols.length;d++)if((f=h.symbols[d])&&f.parts)for(c=0;c<f.parts.length;c++){var k=f.parts[c];k.part&&
(b+="["+k.part+"] ");b+=k.means.map(function(b){return b}).join("; ");b+=Const.NL}}else if(f.dict_result&&f.dict_result.content&&f.dict_result.content)for(f=f.dict_result.content,b+=Const.NL,d=0;d<f.length;d++)if((k=f[d])&&k.mean)for(c=0;c<k.mean.length;c++){var l=k.mean[c];b+=l.pre+" ";for(h in l.cont)l.cont.hasOwnProperty(h)&&(b+=h);b+=Const.NL}}return new ResponseData(b,e,g)}
function serviceListenRequest(b,d,e){b=format("/text2audio?lan={0}&ie=UTF-8&text={1}",codeFromLanguage(d),encodeGetParam(b));e&&(b+="&spd=1");return new RequestData(HttpMethod.GET,b)};
