-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
163 lines (82 loc) · 2.81 KB
/
index.html
File metadata and controls
163 lines (82 loc) · 2.81 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Translation Shuffler</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
#translate-output {
font-weight: bold;
margin-bottom: 10px;
}
#shuffle-button {
padding: 10px 20px;
font-size: 16px;
}
</style>
</head>
<body>
<h1>Translation Shuffler</h1>
<textarea id="translate-input" rows="5" cols="50" placeholder="Enter text to translate"></textarea>
<br>
<button id="shuffle-button">Start Shuffle</button>
<div id="translate-output"></div>
<script>
// Translations array
const translations = [
{ language: 'Spanish', code: 'es' },
{ language: 'French', code: 'fr' },
{ language: 'German', code: 'de' },
{ language: 'Chinese', code: 'zh' },
{ language: 'Japanese', code: 'ja' },
{ language: 'Korean', code: 'ko' },
{ language: 'Italian', code: 'it' },
{ language: 'Russian', code: 'ru' },
{ language: 'Portuguese', code: 'pt' },
];
// Function to translate text using Google Translate API
function translateText(text, targetLanguage) {
const apiKey = 'YOUR_GOOGLE_TRANSLATE_API_KEY';
const url = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;
const data = {
q: text,
target: targetLanguage
};
return fetch(url, {
method: 'POST',
body: JSON.stringify(data)
})
.then(response => response.json())
.then(json => json.data.translations[0].translatedText);
}
// Function to shuffle translations randomly
function shuffleTranslations(translations) {
for (let i = translations.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[translations[i], translations[j]] = [translations[j], translations[i]];
}
}
// Event listener for the shuffle button
document.getElementById('shuffle-button').addEventListener('click', function () {
const inputText = document.getElementById('translate-input').value;
const outputDiv = document.getElementById('translate-output');
outputDiv.innerHTML = '';
// Shuffle translations randomly
shuffleTranslations(translations);
// Translate and display text for each language
translations.forEach((translation, index) => {
setTimeout(() => {
translateText(inputText, translation.code)
.then(translatedText => {
outputDiv.innerHTML += `<p><strong>${translation.language}:</strong> ${translatedText}</p>`;
});
}, index * 1000); // Change the delay here (in milliseconds) to adjust the translation speed
});
});
</script>
</body>
</html>