-
Notifications
You must be signed in to change notification settings - Fork 3
/
yatranslate.min.js
3 lines (3 loc) · 1.3 KB
/
yatranslate.min.js
1
2
3
window.yaTranslate=function(l,d,f,m){var b={en:{ru:1},ru:{en:2,uk:4},uk:{ru:8}};typeof window.console=="undefined"&&(console={warn:function(){}});if(arguments.length<4)console.warn("Function yaTranslate accept 4 arguments:\n1. text \u2014 Text that need to translate\n2. originLang \u2014 Original language of the text\n3. targetLang \u2014 In which language text would be translated\n4. callback \u2014 Callback which will be invoked when the text would be translatedand this translated text will be passed as first argument of this callback");
else if(!b[d]||!(f in b[d]))console.warn('Yandex Translate can not produce translation from "'+d+'" to "'+f+'"');else{for(var b=l.split("."),j=[],c=[],a=0,g=0,n=b.length;g<n;g++){var e=encodeURIComponent(b[g]);c[a]&&c[a].length>=2E3&&(a+=1);c[a]?c[a].length<2E3&&c[a].length+(e.length+1)<2E3?c[a]+="."+e:(a+=1,c[a]="."+e):c[a]=e}var a=0,h=(new Date).getTime(),k=function(){var i=document.createElement("script"),b=["callback=_tmp_translate_callback_"+h,"lang="+d+"-"+f,"srv=tr-text","id=adb7aca1-0-0",
"text="+c[a]];i.type="text/javascript";i.src="http://translate.yandex.ru/tr.json/translate?"+b.join("&");document.body.appendChild(i)};window["_tmp_translate_callback_"+h]=function(b){a+=1;b&&j.push(b);c.length==a?(delete window["_tmp_translate_callback_"+h],m(j.join("."))):k()};k()}};