This file contains 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 nodeFetch = require("node-fetch"), request = require("request"), say = require("say"); | |
async function translate(text) { | |
text = text.replace(/^Translate to/i).trim(); | |
//Extracts the text to translated from the text inputted | |
const textToTranslate = text.replace(text.split(" ")[1], "").replace(undefined, "").trim(); | |
const url = encodeURI(`https://en.wikipedia.org/w/api.php?action=languagesearch&search=${text.split(" ")[1]}&format=json`); | |
//Sends a request to Wikipedia to fetch the language code | |
let langResponse = await nodeFetch(url, { | |
method: 'GET', |