Skip to content

Instantly share code, notes, and snippets.

@Gyvastis
Created October 28, 2020 08:53
Show Gist options
  • Select an option

  • Save Gyvastis/7b22a883c3f6443e9656b6e27a29c02f to your computer and use it in GitHub Desktop.

Select an option

Save Gyvastis/7b22a883c3f6443e9656b6e27a29c02f to your computer and use it in GitHub Desktop.

Revisions

  1. Gyvastis created this gist Oct 28, 2020.
    13 changes: 13 additions & 0 deletions translate.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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)