Skip to content

Instantly share code, notes, and snippets.

@Gyvastis
Created October 28, 2020 08:53
Show Gist options
  • Save Gyvastis/7b22a883c3f6443e9656b6e27a29c02f to your computer and use it in GitHub Desktop.
Save Gyvastis/7b22a883c3f6443e9656b6e27a29c02f to your computer and use it in GitHub Desktop.
Bing translate
const translate = text => fetch("https://www.bing.com/ttranslatev3", {
"headers": {
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36",
"content-type": "application/x-www-form-urlencoded",
},
"body": `&fromLang=nb&text=${encodeURIComponent(text)}&to=en`,
"method": "POST",
"mode": "cors"
})
.then(response => response.json())
.then(json => json[0].translations[0].text);
translate('vann').then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment