Added google api translation script

This commit is contained in:
Gres 2018-12-24 20:26:47 +03:00
parent 49c5659334
commit 1e3411bd58
2 changed files with 32 additions and 0 deletions

27
translators/google_api.js Normal file
View File

@ -0,0 +1,27 @@
function httpGetAsync(theUrl, callback)
{
console.log(theUrl);
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true);
xmlHttp.send(null);
}
function translate (){
var url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl='
+ st_wtp.resultLanguage + '&dt=t&q=' + st_wtp.sourceText;
httpGetAsync(url, function(responce) {
console.log(responce);
var object = JSON.parse(responce);
var result = '';
object[0].forEach(function(element) {
result += element[0] + ' ';
});
console.log(object);
st_wtp.translated (result);
});
}

View File

@ -22,6 +22,11 @@
"url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js",
"path": "translators/google.js"
},
"Google API translator": {
"version": 1,
"url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google_api.js",
"path": "translators/google_api.js"
},
"Yandex translator": {
"version": 4,
"url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js",