23 lines
814 B
JavaScript
23 lines
814 B
JavaScript
const axios = require('axios');
|
|
|
|
const subscriptionKey = '54FyVMKaRBATXAy2QKhEL1USlgrIlAGVHJVO9rjynnKGcZA0S2KtJQQJ99BDAC5RqLJXJ3w3AAAbACOGuFGT'; // заменено на ваш ключ
|
|
const endpoint = 'https://aimpress-translator.cognitiveservices.azure.com/';
|
|
|
|
async function translateText(text, targetLanguage) {
|
|
try {
|
|
const response = await axios.post(`${endpoint}/translate?api-version=3.0&to=${targetLanguage}`, [{
|
|
Text: text
|
|
}], {
|
|
headers: {
|
|
'Ocp-Apim-Subscription-Key': subscriptionKey,
|
|
'Content-Type': 'application/json'
|
|
}
|
|
});
|
|
|
|
return response.data[0].translations[0].text;
|
|
} catch (error) {
|
|
console.error('Error during translation:', error);
|
|
}
|
|
}
|
|
|
|
module.exports = { translateText };
|