Skip to content

Instantly share code, notes, and snippets.

@BMU-Verlag
Created December 19, 2019 16:55
Show Gist options
  • Save BMU-Verlag/71ea262b00c46aef5e544d8455bcf693 to your computer and use it in GitHub Desktop.
Save BMU-Verlag/71ea262b00c46aef5e544d8455bcf693 to your computer and use it in GitHub Desktop.
function translateText() {
var input = document.getElementById("input").value;
var languages = document.getElementById("source_language").value + "-" + document.getElementById("target_language").value;
var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=<API-key>&text=" + input + "&lang=" + languages;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("translated_text").value = JSON.parse(this.responseText)["text"][0];
}
};
xhttp.open("POST", url, true);
xhttp.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment