Added google api translation script
This commit is contained in:
		
							parent
							
								
									49c5659334
								
							
						
					
					
						commit
						1e3411bd58
					
				
							
								
								
									
										27
									
								
								translators/google_api.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								translators/google_api.js
									
									
									
									
									
										Normal 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);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -22,6 +22,11 @@
 | 
				
			|||||||
        "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js",
 | 
					        "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js",
 | 
				
			||||||
        "path": "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": {
 | 
					    "Yandex translator": {
 | 
				
			||||||
        "version": 4,
 | 
					        "version": 4,
 | 
				
			||||||
        "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js",
 | 
					        "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js",
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user