Created
November 18, 2019 08:03
-
-
Save keicoon/f6dce34c3a4a1112262440d9cee84c7e to your computer and use it in GitHub Desktop.
code snippet about google translate resutful api in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Promise((resolve, reject) => { | |
var apiKey = GetGoogleSecret(); | |
var { source, target } = GetRegion(text); | |
var apiurl = "https://www.googleapis.com/language/translate/v2?key=" + apiKey + "&source=" + source + "&target=" + target + "&q="; | |
$.ajax({ | |
url: apiurl + encodeURIComponent(text), | |
dataType: 'jsonp', | |
success: function(data) { | |
var result = data.data.translations[0].translatedText; | |
resolve(result) | |
}, | |
error: function(err) { | |
reject(err) | |
} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment