"use strict";var t=require("@vitalets/google-translate-api"),r=require("proxy-agent"),e=require("got"),a=require("md5"),n=require("qs");exports.baiduTranslate=function(t){return r=this,o=arguments,i=function*({word:t,originLang:r,targetLang:o,option:i}){const s=i.key,c=i.secret,p=Math.random(),u=a(s+t+p+c),g={from:r,to:o.split("-")[0],appid:s,salt:p,sign:u,q:t},l=`https://fanyi-api.baidu.com/api/trans/vip/translate?${n.stringify(g)}`;try{const t=yield e.get(l),r=JSON.parse(t.body);return r.error_code?t.body:r.trans_result}catch(t){return t}},new Promise(((t,e)=>{var a=t=>{try{s(i.next(t))}catch(t){e(t)}},n=t=>{try{s(i.throw(t))}catch(t){e(t)}},s=r=>r.done?t(r.value):Promise.resolve(r.value).then(a,n);s((i=i.apply(r,o)).next())}));var r,o,i},exports.googleTranslate=function({word:e,originLang:a,targetLang:n,proxy:o}){return new Promise(((i,s)=>{const c=r(o);t.translate(e,{fetchOptions:{agent:c},from:a,to:n}).then((t=>{i(t.text||"")})).catch((t=>{s(t)}))}))},exports.youdaoTranslate=function(t){return r=this,o=arguments,i=function*({word:t,originLang:r,targetLang:o,option:i}){const s=i.key,c=i.secret,p=Math.random(),u={from:r,to:o,appKey:s,salt:p,sign:a(s+t+p+c),q:t},g=`https://openapi.youdao.com/api?${n.stringify(u)}`;try{const t=yield e.get(g),r=JSON.parse(t.body);return"0"===r.errorCode?r.translation[0]:t.body}catch(t){return t}},new Promise(((t,e)=>{var a=t=>{try{s(i.next(t))}catch(t){e(t)}},n=t=>{try{s(i.throw(t))}catch(t){e(t)}},s=r=>r.done?t(r.value):Promise.resolve(r.value).then(a,n);s((i=i.apply(r,o)).next())}));var r,o,i};