-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslater.html
More file actions
79 lines (69 loc) · 2.67 KB
/
Copy pathtranslater.html
File metadata and controls
79 lines (69 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Простой переводчик</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
#translator {
width: 400px;
margin: 0 auto;
}
textarea {
width: 100%;
height: 100px;
margin-bottom: 10px;
}
button {
padding: 10px;
cursor: pointer;
}
#result {
margin-top: 20px;
}
</style>
</head>
<body>
<div id="translator">
<h2>Простой переводчик</h2>
<textarea id="inputText" placeholder="Введите текст для перевода"></textarea>
<button onclick="translate()">Перевести</button>
<div id="result"></div>
</div>
<script>
async function translate() {
const inputText = document.getElementById('inputText').value;
const resultDiv = document.getElementById('result');
// Здесь вы можете использовать API для перевода, например, Google Translate API или Yandex.Translate API
// Пожалуйста, замените 'YOUR_API_KEY' на ваш ключ API.
// Пример с Google Translate API (требуется API-ключ):
const apiKey = 'YOUR_API_KEY';
const targetLanguage = 'ru';
const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
q: inputText,
target: targetLanguage,
}),
});
const data = await response.json();
// Вывести результат на страницу
if (data.data && data.data.translations && data.data.translations.length > 0) {
const translatedText = data.data.translations[0].translatedText;
resultDiv.innerHTML = `<p><strong>Переведенный текст:</strong> ${translatedText}</p>`;
} else {
resultDiv.innerHTML = '<p>Ошибка при переводе текста.</p>';
}
}
</script>
</body>
</html>