-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (18 loc) · 907 Bytes
/
Copy pathindex.js
File metadata and controls
22 lines (18 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const googleTranslate = require('google-translate-api');
//To use this code, you'll need to install the google-translate-api package using npm:
//npm install google-translate-api
const sourceLanguageInput = document.getElementById('source-language');
const targetLanguageInput = document.getElementById('target-language');
const sourceTextInput = document.getElementById('source-text');
const translatedTextInput = document.getElementById('translated-text');
const translateButton = document.getElementById('translate-button');
translateButton.addEventListener('click', async () => {
const sourceLanguage = sourceLanguageInput.value;
const targetLanguage = targetLanguageInput.value;
const sourceText = sourceTextInput.value;
const translatedText = await googleTranslate(sourceText, {
from: sourceLanguage,
to: targetLanguage
});
translatedTextInput.value = translatedText.text;
});