var request = require("request-promise");
var apiKey = process.env.YANDEX_API_KEY;
async function yandex(method, opts)
{
var url = "https://translate.yandex.net/api/v1.5/tr.json/" + method + "?";
url += Object.keys(opts).map(function(key){
return key+"="+encodeURIComponent(opts[key])
}).concat("key="+apiKey).join("&")
return request.get(url);
}
module.exports.languages = async function languages()
{
return JSON.parse(await yandex("getLangs", { ui: "en" })).langs;
}
module.exports.translate = async function translate(from, to, text)
{
var response = await yandex("translate", {text: text, lang: from+"-"+to})
return JSON.parse(response).text[0]
}
//to use, make sure you set:
process.env.YANDEX_API_KEY
Translation, powered by Yandex. For more information, see http://translate.yandex.com/
You can get your own key at: https://tech.yandex.com/keys/get/?service=trnsl