Last active
July 28, 2019 06:58
-
-
Save Richienb/1269f654756b7f93e1bc0c1b222c0ca5 to your computer and use it in GitHub Desktop.
Google Translate API
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
| const sourceLang = "en" | |
| const targetLang = "id" | |
| const sourceText = "Hello" | |
| const translate = (sourceLang, targetLang, sourceText) => new Promise((resolve, reject) => { | |
| $.getJSON(`https://translate.googleapis.com/translate_a/single`, { | |
| client: "gtx", | |
| sl: sourceLang, | |
| tl: targetLang, | |
| dt: "t", | |
| q: encodeURI(sourceText) | |
| }).promise().then(data => resolve(data[0][0][0])) | |
| }) | |
| translate("en", "id", "Hello").then(console.log) // "Halo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment