Friday, 1 September 2023

Translation service


Yandex Translation Service

Simple Yandex Translation Service

Translated Text:

function translateText() { const sourceText = document.getElementById('sourceText').value; const targetLanguage = document.getElementById('targetLanguage').value; const apiKey = 'trnsl.1.1.20180722T175752Z.34c48a38d0ac3bd0.5485ce366a8efa29beb80efafb6460c070bfb382'; // The target language should be specified as 'en-TARGET_LANGUAGE' const url = `https://translate.yandex.net/api/v1.5/tr.json/translate?key=${apiKey}&text=${encodeURI(sourceText)}&lang=en-${targetLanguage}`; fetch(url) .then(response => response.json()) .then(data => { const translatedText = data.text[0]; document.getElementById('translatedText').value = translatedText; }) .catch(error => { console.error("There was an error with the translation request:", error); }); }

No comments:

Post a Comment