Spaces:
Running
Running
lewiskimaru
commited on
Create translator.html
Browse files
modules/templates/translator.html
ADDED
@@ -0,0 +1,383 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
|
4 |
+
<head>
|
5 |
+
<meta charset="utf-8">
|
6 |
+
<title>Sema Translator</title>
|
7 |
+
<style>
|
8 |
+
body {
|
9 |
+
font-family: 'Arial', sans-serif;
|
10 |
+
margin: 0;
|
11 |
+
padding: 0;
|
12 |
+
background-color: #f4f4f4;
|
13 |
+
}
|
14 |
+
|
15 |
+
.container {
|
16 |
+
display: flex;
|
17 |
+
justify-content: space-around;
|
18 |
+
align-items: center;
|
19 |
+
margin: 50px 0;
|
20 |
+
}
|
21 |
+
|
22 |
+
.text-box {
|
23 |
+
background-color: #fff;
|
24 |
+
border-radius: 8px;
|
25 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
26 |
+
padding: 20px;
|
27 |
+
width: 45%;
|
28 |
+
}
|
29 |
+
|
30 |
+
select,
|
31 |
+
textarea {
|
32 |
+
width: 100%;
|
33 |
+
padding: 10px;
|
34 |
+
margin-bottom: 15px;
|
35 |
+
border: 1px solid #ccc;
|
36 |
+
border-radius: 4px;
|
37 |
+
box-sizing: border-box;
|
38 |
+
}
|
39 |
+
|
40 |
+
textarea {
|
41 |
+
height: 150px;
|
42 |
+
}
|
43 |
+
|
44 |
+
input[type="submit"] {
|
45 |
+
background-color: #4caf50;
|
46 |
+
color: #fff;
|
47 |
+
border: none;
|
48 |
+
padding: 10px 20px;
|
49 |
+
font-size: 16px;
|
50 |
+
cursor: pointer;
|
51 |
+
border-radius: 4px;
|
52 |
+
}
|
53 |
+
|
54 |
+
input[type="submit"]:hover {
|
55 |
+
background-color: #2674d4;
|
56 |
+
}
|
57 |
+
|
58 |
+
#output:disabled {
|
59 |
+
background-color: #f4f4f4;
|
60 |
+
color: #555;
|
61 |
+
}
|
62 |
+
|
63 |
+
h1 {
|
64 |
+
text-align: center;
|
65 |
+
color: #333;
|
66 |
+
}
|
67 |
+
|
68 |
+
</style>
|
69 |
+
</head>
|
70 |
+
|
71 |
+
<body>
|
72 |
+
<h1>Translate and Detect Source Language</h1>
|
73 |
+
|
74 |
+
<form action="#" method="post" id="translationForm">
|
75 |
+
<div class="container">
|
76 |
+
<div class="text-box input-box">
|
77 |
+
<label for="source_lang">Select source language:</label>
|
78 |
+
<select id="source_lang" name="source_lang"></select>
|
79 |
+
<textarea id="userinput" name="userinput" placeholder="Enter text"></textarea>
|
80 |
+
</div>
|
81 |
+
|
82 |
+
<div class="text-box output-box">
|
83 |
+
<label for="target_lang">Select target language:</label>
|
84 |
+
<select id="target_lang" name="target_lang"></select>
|
85 |
+
<textarea id="output" name="output" placeholder="Translation" disabled></textarea>
|
86 |
+
</div>
|
87 |
+
</div>
|
88 |
+
|
89 |
+
<input type="submit" value="Translate">
|
90 |
+
</form>
|
91 |
+
|
92 |
+
<script>
|
93 |
+
document.addEventListener('DOMContentLoaded', function () {
|
94 |
+
const form = document.querySelector('#translationForm');
|
95 |
+
const targetLangSelect = document.querySelector('#target_lang');
|
96 |
+
const sourceLangSelect = document.querySelector('#source_lang');
|
97 |
+
const userInput = document.querySelector('#userinput');
|
98 |
+
const outputText = document.querySelector('#output');
|
99 |
+
|
100 |
+
// Define your languages and codes
|
101 |
+
const languages = [
|
102 |
+
{ name: 'Acehnese (Latin script)', code: 'ace_Latn' },
|
103 |
+
{ name: 'Mesopotamian Arabic', code: 'acm_Arab' },
|
104 |
+
{ name: 'Ta’izzi-Adeni Arabic', code: 'acq_Arab' },
|
105 |
+
{ name: 'Tunisian Arabic', code: 'aeb_Arab' },
|
106 |
+
{ name: 'Afrikaans', code: 'afr_Latn' },
|
107 |
+
{ name: 'South Levantine Arabic', code: 'ajp_Arab' },
|
108 |
+
{ name: 'Akan', code: 'aka_Latn' },
|
109 |
+
{ name: 'Amharic', code: 'amh_Ethi' },
|
110 |
+
{ name: 'North Levantine Arabic', code: 'apc_Arab' },
|
111 |
+
{ name: 'Modern Standard Arabic', code: 'arb_Arab' },
|
112 |
+
{ name: 'Modern Standard Arabic (Romanized)', code: 'arb_Latn' },
|
113 |
+
{ name: 'Najdi Arabic', code: 'ars_Arab' },
|
114 |
+
{ name: 'Moroccan Arabic', code: 'ary_Arab' },
|
115 |
+
{ name: 'Egyptian Arabic', code: 'arz_Arab' },
|
116 |
+
{ name: 'Assamese', code: 'asm_Beng' },
|
117 |
+
{ name: 'Asturian', code: 'ast_Latn' },
|
118 |
+
{ name: 'Awadhi', code: 'awa_Deva' },
|
119 |
+
{ name: 'Central Aymara', code: 'ayr_Latn' },
|
120 |
+
{ name: 'South Azerbaijani', code: 'azb_Arab' },
|
121 |
+
{ name: 'North Azerbaijani', code: 'azj_Latn' },
|
122 |
+
{ name: 'Bashkir', code: 'bak_Cyrl' },
|
123 |
+
{ name: 'Bambara', code: 'bam_Latn' },
|
124 |
+
{ name: 'Balinese', code: 'ban_Latn' },
|
125 |
+
{ name: 'Belarusian', code: 'bel_Cyrl' },
|
126 |
+
{ name: 'Bemba', code: 'bem_Latn' },
|
127 |
+
{ name: 'Bengali', code: 'ben_Beng' },
|
128 |
+
{ name: 'Bhojpuri', code: 'bho_Deva' },
|
129 |
+
{ name: 'Banjar (Arabic script)', code: 'bjn_Arab' },
|
130 |
+
{ name: 'Banjar (Latin script)', code: 'bjn_Latn' },
|
131 |
+
{ name: 'Standard Tibetan', code: 'bod_Tibt' },
|
132 |
+
{ name: 'Bosnian', code: 'bos_Latn' },
|
133 |
+
{ name: 'Buginese', code: 'bug_Latn' },
|
134 |
+
{ name: 'Bulgarian', code: 'bul_Cyrl' },
|
135 |
+
{ name: 'Catalan', code: 'cat_Latn' },
|
136 |
+
{ name: 'Cebuano', code: 'ceb_Latn' },
|
137 |
+
{ name: 'Czech', code: 'ces_Latn' },
|
138 |
+
{ name: 'Chokwe', code: 'cjk_Latn' },
|
139 |
+
{ name: 'Central Kurdish', code: 'ckb_Arab' },
|
140 |
+
{ name: 'Crimean Tatar', code: 'crh_Latn' },
|
141 |
+
{ name: 'Welsh', code: 'cym_Latn' },
|
142 |
+
{ name: 'Danish', code: 'dan_Latn' },
|
143 |
+
{ name: 'German', code: 'deu_Latn' },
|
144 |
+
{ name: 'Southwestern Dinka', code: 'dik_Latn' },
|
145 |
+
{ name: 'Dyula', code: 'dyu_Latn' },
|
146 |
+
{ name: 'Dzongkha', code: 'dzo_Tibt' },
|
147 |
+
{ name: 'Greek', code: 'ell_Grek' },
|
148 |
+
{ name: 'English', code: 'eng_Latn' },
|
149 |
+
{ name: 'Esperanto', code: 'epo_Latn' },
|
150 |
+
{ name: 'Estonian', code: 'est_Latn' },
|
151 |
+
{ name: 'Basque', code: 'eus_Latn' },
|
152 |
+
{ name: 'Ewe', code: 'ewe_Latn' },
|
153 |
+
{ name: 'Faroese', code: 'fao_Latn' },
|
154 |
+
{ name: 'Fijian', code: 'fij_Latn' },
|
155 |
+
{ name: 'Finnish', code: 'fin_Latn' },
|
156 |
+
{ name: 'Fon', code: 'fon_Latn' },
|
157 |
+
{ name: 'French', code: 'fra_Latn' },
|
158 |
+
{ name: 'Friulian', code: 'fur_Latn' },
|
159 |
+
{ name: 'Nigerian Fulfulde', code: 'fuv_Latn' },
|
160 |
+
{ name: 'Scottish Gaelic', code: 'gla_Latn' },
|
161 |
+
{ name: 'Irish', code: 'gle_Latn' },
|
162 |
+
{ name: 'Galician', code: 'glg_Latn' },
|
163 |
+
{ name: 'Guarani', code: 'grn_Latn' },
|
164 |
+
{ name: 'Gujarati', code: 'guj_Gujr' },
|
165 |
+
{ name: 'Haitian Creole', code: 'hat_Latn' },
|
166 |
+
{ name: 'Hausa', code: 'hau_Latn' },
|
167 |
+
{ name: 'Hebrew', code: 'heb_Hebr' },
|
168 |
+
{ name: 'Hindi', code: 'hin_Deva' },
|
169 |
+
{ name: 'Chhattisgarhi', code: 'hne_Deva' },
|
170 |
+
{ name: 'Croatian', code: 'hrv_Latn' },
|
171 |
+
{ name: 'Hungarian', code: 'hun_Latn' },
|
172 |
+
{ name: 'Armenian', code: 'hye_Armn' },
|
173 |
+
{ name: 'Igbo', code: 'ibo_Latn' },
|
174 |
+
{ name: 'Ilocano', code: 'ilo_Latn' },
|
175 |
+
{ name: 'Indonesian', code: 'ind_Latn' },
|
176 |
+
{ name: 'Icelandic', code: 'isl_Latn' },
|
177 |
+
{ name: 'Italian', code: 'ita_Latn' },
|
178 |
+
{ name: 'Javanese', code: 'jav_Latn' },
|
179 |
+
{ name: 'Japanese', code: 'jpn_Jpan' },
|
180 |
+
{ name: 'Kabyle', code: 'kab_Latn' },
|
181 |
+
{ name: 'Jingpho', code: 'kac_Latn' },
|
182 |
+
{ name: 'Kamba', code: 'kam_Latn' },
|
183 |
+
{ name: 'Kannada', code: 'kan_Knda' },
|
184 |
+
{ name: 'Kashmiri (Arabic script)', code: 'kas_Arab' },
|
185 |
+
{ name: 'Kashmiri (Devanagari script)', code: 'kas_Deva' },
|
186 |
+
{ name: 'Georgian', code: 'kat_Geor' },
|
187 |
+
{ name: 'Central Kanuri (Arabic script)', code: 'knc_Arab' },
|
188 |
+
{ name: 'Central Kanuri (Latin script)', code: 'knc_Latn' },
|
189 |
+
{ name: 'Kazakh', code: 'kaz_Cyrl' },
|
190 |
+
{ name: 'Kabiyè', code: 'kbp_Latn' },
|
191 |
+
{ name: 'Kabuverdianu', code: 'kea_Latn' },
|
192 |
+
{ name: 'Khmer', code: 'khm_Khmr' },
|
193 |
+
{ name: 'Kikuyu', code: 'kik_Latn' },
|
194 |
+
{ name: 'Kinyarwanda', code: 'kin_Latn' },
|
195 |
+
{ name: 'Kyrgyz', code: 'kir_Cyrl' },
|
196 |
+
{ name: 'Kimbundu', code: 'kmb_Latn' },
|
197 |
+
{ name: 'Northern Kurdish', code: 'kmr_Latn' },
|
198 |
+
{ name: 'Kikongo', code: 'kon_Latn' },
|
199 |
+
{ name: 'Korean', code: 'kor_Hang' },
|
200 |
+
{ name: 'Lao', code: 'lao_Laoo' },
|
201 |
+
{ name: 'Ligurian', code: 'lij_Latn' },
|
202 |
+
{ name: 'Limburgish', code: 'lim_Latn' },
|
203 |
+
{ name: 'Lingala', code: 'lin_Latn' },
|
204 |
+
{ name: 'Lithuanian', code: 'lit_Latn' },
|
205 |
+
{ name: 'Lombard', code: 'lmo_Latn' },
|
206 |
+
{ name: 'Latgalian', code: 'ltg_Latn' },
|
207 |
+
{ name: 'Luxembourgish', code: 'ltz_Latn' },
|
208 |
+
{ name: 'Luba-Kasai', code: 'lua_Latn' },
|
209 |
+
{ name: 'Ganda', code: 'lug_Latn' },
|
210 |
+
{ name: 'Luo', code: 'luo_Latn' },
|
211 |
+
{ name: 'Mizo', code: 'lus_Latn' },
|
212 |
+
{ name: 'Standard Latvian', code: 'lvs_Latn' },
|
213 |
+
{ name: 'Magahi', code: 'mag_Deva' },
|
214 |
+
{ name: 'Maithili', code: 'mai_Deva' },
|
215 |
+
{ name: 'Malayalam', code: 'mal_Mlym' },
|
216 |
+
{ name: 'Marathi', code: 'mar_Deva' },
|
217 |
+
{ name: 'Minangkabau (Arabic script)', code: 'min_Arab' },
|
218 |
+
{ name: 'Minangkabau (Latin script)', code: 'min_Latn' },
|
219 |
+
{ name: 'Macedonian', code: 'mkd_Cyrl' },
|
220 |
+
{ name: 'Plateau Malagasy', code: 'plt_Latn' },
|
221 |
+
{ name: 'Maltese', code: 'mlt_Latn' },
|
222 |
+
{ name: 'Meitei (Bengali script)', code: 'mni_Beng' },
|
223 |
+
{ name: 'Halh Mongolian', code: 'khk_Cyrl' },
|
224 |
+
{ name: 'Mossi', code: 'mos_Latn' },
|
225 |
+
{ name: 'Maori', code: 'mri_Latn' },
|
226 |
+
{ name: 'Burmese', code: 'mya_Mymr' },
|
227 |
+
{ name: 'Dutch', code: 'nld_Latn' },
|
228 |
+
{ name: 'Norwegian Nynorsk', code: 'nno_Latn' },
|
229 |
+
{ name: 'Norwegian Bokmål', code: 'nob_Latn' },
|
230 |
+
{ name: 'Nepali', code: 'npi_Deva' },
|
231 |
+
{ name: 'Northern Sotho', code: 'nso_Latn' },
|
232 |
+
{ name: 'Nuer', code: 'nus_Latn' },
|
233 |
+
{ name: 'Nyanja', code: 'nya_Latn' },
|
234 |
+
{ name: 'Occitan', code: 'oci_Latn' },
|
235 |
+
{ name: 'West Central Oromo', code: 'gaz_Latn' },
|
236 |
+
{ name: 'Odia', code: 'ory_Orya' },
|
237 |
+
{ name: 'Pangasinan', code: 'pag_Latn' },
|
238 |
+
{ name: 'Eastern Panjabi', code: 'pan_Guru' },
|
239 |
+
{ name: 'Papiamento', code: 'pap_Latn' },
|
240 |
+
{ name: 'Western Persian', code: 'pes_Arab' },
|
241 |
+
{ name: 'Polish', code: 'pol_Latn' },
|
242 |
+
{ name: 'Portuguese', code: 'por_Latn' },
|
243 |
+
{ name: 'Dari', code: 'prs_Arab' },
|
244 |
+
{ name: 'Southern Pashto', code: 'pbt_Arab' },
|
245 |
+
{ name: 'Ayacucho Quechua', code: 'quy_Latn' },
|
246 |
+
{ name: 'Romanian', code: 'ron_Latn' },
|
247 |
+
{ name: 'Rundi', code: 'run_Latn' },
|
248 |
+
{ name: 'Russian', code: 'rus_Cyrl' },
|
249 |
+
{ name: 'Sango', code: 'sag_Latn' },
|
250 |
+
{ name: 'Sanskrit', code: 'san_Deva' },
|
251 |
+
{ name: 'Santali', code: 'sat_Olck' },
|
252 |
+
{ name: 'Sicilian', code: 'scn_Latn' },
|
253 |
+
{ name: 'Shan', code: 'shn_Mymr' },
|
254 |
+
{ name: 'Sinhala', code: 'sin_Sinh' },
|
255 |
+
{ name: 'Slovak', code: 'slk_Latn' },
|
256 |
+
{ name: 'Slovenian', code: 'slv_Latn' },
|
257 |
+
{ name: 'Slovenian', code: 'slv_Latn' },
|
258 |
+
{ name: 'Samoan', code: 'smo_Latn' },
|
259 |
+
{ name: 'Shona', code: 'sna_Latn' },
|
260 |
+
{ name: 'Sindhi', code: 'snd_Arab' },
|
261 |
+
{ name: 'Somali', code: 'som_Latn' },
|
262 |
+
{ name: 'Southern Sotho', code: 'sot_Latn' },
|
263 |
+
{ name: 'Spanish', code: 'spa_Latn' },
|
264 |
+
{ name: 'Tosk Albanian', code: 'als_Latn' },
|
265 |
+
{ name: 'Sardinian', code: 'srd_Latn' },
|
266 |
+
{ name: 'Serbian', code: 'srp_Cyrl' },
|
267 |
+
{ name: 'Swati', code: 'ssw_Latn' },
|
268 |
+
{ name: 'Sundanese', code: 'sun_Latn' },
|
269 |
+
{ name: 'Swedish', code: 'swe_Latn' },
|
270 |
+
{ name: 'Swahili', code: 'swh_Latn' },
|
271 |
+
{ name: 'Silesian', code: 'szl_Latn' },
|
272 |
+
{ name: 'Tamil', code: 'tam_Taml' },
|
273 |
+
{ name: 'Tatar', code: 'tat_Cyrl' },
|
274 |
+
{ name: 'Telugu', code: 'tel_Telu' },
|
275 |
+
{ name: 'Tajik', code: 'tgk_Cyrl' },
|
276 |
+
{ name: 'Tagalog', code: 'tgl_Latn' },
|
277 |
+
{ name: 'Thai', code: 'tha_Thai' },
|
278 |
+
{ name: 'Tigrinya', code: 'tir_Ethi' },
|
279 |
+
{ name: 'Tamasheq (Latin script)', code: 'taq_Latn' },
|
280 |
+
{ name: 'Tamasheq (Tifinagh script)', code: 'taq_Tfng' },
|
281 |
+
{ name: 'Tok Pisin', code: 'tpi_Latn' },
|
282 |
+
{ name: 'Tswana', code: 'tsn_Latn' },
|
283 |
+
{ name: 'Tsonga', code: 'tso_Latn' },
|
284 |
+
{ name: 'Turkmen', code: 'tuk_Latn' },
|
285 |
+
{ name: 'Tumbuka', code: 'tum_Latn' },
|
286 |
+
{ name: 'Turkish', code: 'tur_Latn' },
|
287 |
+
{ name: 'Twi', code: 'twi_Latn' },
|
288 |
+
{ name: 'Central Atlas Tamazight', code: 'tzm_Tfng' },
|
289 |
+
{ name: 'Uyghur', code: 'uig_Arab' },
|
290 |
+
{ name: 'Ukrainian', code: 'ukr_Cyrl' },
|
291 |
+
{ name: 'Umbundu', code: 'umb_Latn' },
|
292 |
+
{ name: 'Urdu', code: 'urd_Arab' },
|
293 |
+
{ name: 'Northern Uzbek', code: 'uzn_Latn' },
|
294 |
+
{ name: 'Venetian', code: 'vec_Latn' },
|
295 |
+
{ name: 'Vietnamese', code: 'vie_Latn' },
|
296 |
+
{ name: 'Waray', code: 'war_Latn' },
|
297 |
+
{ name: 'Wolof', code: 'wol_Latn' },
|
298 |
+
{ name: 'Xhosa', code: 'xho_Latn' },
|
299 |
+
{ name: 'Eastern Yiddish', code: 'ydd_Hebr' },
|
300 |
+
{ name: 'Yoruba', code: 'yor_Latn' },
|
301 |
+
{ name: 'Yue Chinese', code: 'yue_Hant' },
|
302 |
+
{ name: 'Chinese (Simplified)', code: 'zho_Hans' },
|
303 |
+
{ name: 'Chinese (Traditional)', code: 'zho_Hant' },
|
304 |
+
{ name: 'Standard Malay', code: 'zsm_Latn' },
|
305 |
+
{ name: 'Zulu', code: 'zul_Latn' },
|
306 |
+
];
|
307 |
+
|
308 |
+
// Function to populate the dropdown options
|
309 |
+
function populateDropdown(select, options) {
|
310 |
+
options.forEach((option) => {
|
311 |
+
const optionElem = document.createElement('option');
|
312 |
+
optionElem.value = option.code;
|
313 |
+
optionElem.text = option.name;
|
314 |
+
select.add(optionElem);
|
315 |
+
});
|
316 |
+
}
|
317 |
+
|
318 |
+
// Call the function to populate dropdown options
|
319 |
+
populateDropdown(targetLangSelect, languages);
|
320 |
+
populateDropdown(sourceLangSelect, [{ name: 'Auto Detect', code: 'auto' }, ...languages]);
|
321 |
+
|
322 |
+
form.addEventListener('submit', async (e) => {
|
323 |
+
e.preventDefault();
|
324 |
+
|
325 |
+
const targetLang = targetLangSelect.value;
|
326 |
+
const sourceLang = sourceLangSelect.value;
|
327 |
+
|
328 |
+
try {
|
329 |
+
// Change placeholder text to "Translating..."
|
330 |
+
outputText.placeholder = 'Translating...';
|
331 |
+
|
332 |
+
let sourceLanguage;
|
333 |
+
|
334 |
+
// Check if Auto Detect is selected for source language
|
335 |
+
if (sourceLang === 'auto') {
|
336 |
+
const detectionResponse = await fetch('https://lewiskimaru-helloworld.hf.space/translate_detect/', {
|
337 |
+
method: 'POST',
|
338 |
+
headers: {
|
339 |
+
'Content-Type': 'application/json'
|
340 |
+
},
|
341 |
+
body: JSON.stringify({
|
342 |
+
userinput: userInput.value,
|
343 |
+
target_lang: targetLang
|
344 |
+
})
|
345 |
+
});
|
346 |
+
|
347 |
+
const detectionData = await detectionResponse.json();
|
348 |
+
sourceLanguage = detectionData.source_language;
|
349 |
+
} else {
|
350 |
+
sourceLanguage = sourceLang;
|
351 |
+
}
|
352 |
+
|
353 |
+
// Check if Auto Detect is selected for target language
|
354 |
+
const targetLanguage = targetLang === 'auto' ? 'eng_Latn' : targetLang;
|
355 |
+
|
356 |
+
const translationResponse = await fetch('https://lewiskimaru-helloworld.hf.space/translate_enter/', {
|
357 |
+
method: 'POST',
|
358 |
+
headers: {
|
359 |
+
'Content-Type': 'application/json'
|
360 |
+
},
|
361 |
+
body: JSON.stringify({
|
362 |
+
userinput: userInput.value,
|
363 |
+
target_lang: targetLanguage,
|
364 |
+
source_lang: sourceLanguage
|
365 |
+
})
|
366 |
+
});
|
367 |
+
|
368 |
+
const translatedText = (await translationResponse.json()).translated_text;
|
369 |
+
|
370 |
+
// Update placeholder with the translated text
|
371 |
+
outputText.placeholder = translatedText;
|
372 |
+
|
373 |
+
} catch (error) {
|
374 |
+
console.error(error);
|
375 |
+
outputText.placeholder = 'An error occurred. Please try again.';
|
376 |
+
}
|
377 |
+
});
|
378 |
+
});
|
379 |
+
|
380 |
+
</script>
|
381 |
+
</body>
|
382 |
+
|
383 |
+
</html>
|