forked from joseprzmoreno/multilingualheadlines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multilingual_headlines.html
354 lines (318 loc) · 19.7 KB
/
multilingual_headlines.html
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!DOCTYPE html>
<html>
<head>
<style>
#todo {
width: 1200px;
padding-top: 10px;
margin-left:auto;
margin-right:auto;
}
#imagenPeriodicos {
width:1198px;
height:1300px;
}
#botonGenerar {
font-color: red;
background-color: grey;
border: 1px solid yellow;
cursor: pointer;
padding:1px;
border-radius:1px;
color:yellow;
}
#cabecera {
padding:10px;
width:1180px;
font-family: 'Raleway', sans-serif;
background-color: lightgrey;
text-align:center;
margin-bottom:10px;
}
#cabeceraTitulo {
font-size: 30px;
font-family: 'Montserrat', sans-serif;
}
#cabeceraExplicacion {
font-size:16px;
margin-bottom:2px;
}
#cabeceraCreditos {
font-size: 12px;
}
#contTitulares {
font-family: 'Roboto Condensed', sans-serif;
}
a {
text-decoration: none;
color: inherit;
font-weight: bold;
}
.linea {
}
.periodico {
margin-bottom:10px;
padding:10px;
width:369px;
min-height:80px;
margin-right:5px;
margin-left:5px;
box-shadow:2px 2px 2px grey;
display:inline-block;
vertical-align:top;
background: -webkit-linear-gradient(gainsboro, ghostwhite); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(gainsboro, ghostwhite); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(gainsboro, ghostwhite); /* For Firefox 3.6 to 15 */
background: linear-gradient(gainsboro, ghostwhite); /* Standard syntax */
}
.nombreLengua {
font-family: 'Raleway', sans-serif;
font-size: 14px;
border-bottom: 1px dotted grey;
margin-bottom: 10px;
}
.titular {
font-size:28px;
font-family: 'Roboto Condensed', sans-serif;
}
#textoAra {
text-align:right;
font-family: 'Tahoma';
}
#textoHeb {
text-align: right;
}
.transcripc {
text-align:left;
font-size: 12px;
margin-top:5px;
margin-bottom:2px;
}
.altavoz {
cursor: pointer;
}
</style>
<meta charset="UTF-8">
<title>Multilingual headlines Generator in 21 languages</title>
<link href='https://fonts.googleapis.com/css?family=News+Cycle:700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Roboto+Condensed&subset=latin,greek,greek-ext,vietnamese,cyrillic-ext,latin-ext,cyrillic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Montserrat' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
var synth = window.speechSynthesis;
var voices = [];
document.addEventListener("keydown", function(event){
if (event.keyCode=='70') {
getInfo();
}
});
function getInfo() {
$.ajax({
url: "http://localhost:41296/headlines.pgf",
type: "get",
data:{command:"random"},
success: function(response) {
mostrarInfo(response);
},
error: function(xhr) {
alert("ha habido un error");
},
cache: false
});
}
function mostrarInfo(info) {
//ara baq cat chi eng fre ger glg gre heb hin hrv ita por que rum rus spa swa tgl tur
//0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
var orden = [17,2,7,1,13,5,12,15,4,6,16,11,8,20,9,0,18,10,3,19,14];
var lenguas = ["Arabic","Basque","Catalan","Chinese","English","French","German","Galician","Greek","Hebrew","Hindi","Croatian","Italian","Portuguese","Quechua","Romanian","Russian","Spanish","Swahili","Tagalog","Turkish"];
var respuesta = "";
for (var i=0; i<orden.length; i++) {
if (i%3==0) {respuesta += "<div class='linea'>";}
respuesta += "<div class='periodico'>";
respuesta += "<div class='nombreLengua'>" + lenguas[orden[i]] + "</div><div class='titular'>";
if (info[0].linearizations[orden[i]].texts.length>1) {
var z = Math.floor(Math.random()*info[0].linearizations[orden[i]].texts.length);
}
else {
var z = 0;
}
var textoOrig = info[0].linearizations[orden[i]].texts[z];
//transcripciones
if (orden[i]==16) { //ruso
var transcripcionRus = transcribirRus(textoOrig);
}
else if (orden[i]==8) { //griego
var transcripcionGri = transcribirGri(textoOrig);
}
else if (orden[i]==9) { //hebreo
var transcripcionHeb = transcribirHeb(textoOrig);
}
else if (orden[i]==0) { //arabe
var transcripcionAra = transcribirAra(textoOrig);
}
else if (orden[i]==10) { //hindi
var transcripcionHin = transcribirHin(textoOrig);
}
else if (orden[i]==3) { //chino
var transcripcionChi = transcribirChi(textoOrig);
}
var textoMod = textoOrig.substring(0,1).toUpperCase() + textoOrig.substring(1,textoOrig.length);
var letra = "'";
var re = new RegExp(letra, "g");
textoMod = textoMod.replace(re,"’");
textoOrig = textoOrig.replace(re,"’");
if (orden[i]==9) {
respuesta += "<div class='textoOtr' id='textoHeb'>" + textoMod;
}
else if (orden[i]==0) {
respuesta += "<div class='textoOtr' id='textoAra'>" + textoMod;
}
else if (orden[i]==3) {
respuesta += "<div class='textoOtr' id='textoChi'>" + textoMod.replace(/\s+/g, '');
}
else {
respuesta += "<div class='textoOtr'>" + textoMod;
}
switch (orden[i]) {
case 17:
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("es-ES", "" + textoOrig + "")'></img>";
break;
case 13: //por
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("pt-BR", "" + textoOrig + "")'></img>";
break;
case 5: //fra
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("fr-FR", "" + textoOrig + "")'></img>";
break;
case 12: //ita
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("it-IT", "" + textoOrig + "")'></img>";
break;
case 4: //eng
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("en-US", "" + textoOrig + "")'></img>";
break;
case 6: //ger
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("de-DE", "" + textoOrig + "")'></img>";
break;
case 16: //rus
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("ru-RU", "" + textoOrig + "")'></img>";
break;
case 10: //hin
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("hi-IN", "" + textoOrig + "")'></img>";
break;
case 3: //chi
respuesta += " <img src='https://upload.wikimedia.org/wikipedia/commons/3/3c/Speakerlink.svg' class='altavoz' onclick='decir("zh-CN", "" + textoOrig + "")'></img>";
break;
}
respuesta += "</div>";
if (orden[i]==16) { //ruso
respuesta += "<div class='transcripc'>" + transcripcionRus + "</div>";
}
else if (orden[i]==8) { //griego
respuesta += "<div class='transcripc'>" + transcripcionGri + "</div>";
}
else if (orden[i]==9) { //hebreo
respuesta += "<div class='transcripc'>" + transcripcionHeb + "</div>";
}
else if (orden[i]==0) { //arabe
respuesta += "<div class='transcripc'>" + transcripcionAra + "</div>";
}
else if (orden[i]==10) { //hindi
respuesta += "<div class='transcripc'>" + transcripcionHin + "</div>";
}
else if (orden[i]==3) { //chino
respuesta += "<div class='transcripc'>" + transcripcionChi + "</div>";
}
respuesta += "</div></div>";
if (i%3==2 || i==orden.length-1) {respuesta += "</div>";}
}
document.getElementById("contTitulares").innerHTML = respuesta;
}
function transcribirRus(txt) {
var alfRus = ['актер','Актер', 'а','б','в','г','д','е','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', 'А','Б','В','Г','Д','Е','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я'];
var equivRus = ['aktyor','Aktyor','a','b','v','g','d','e','zh','z','i','j','k','l','m','n','o','p','r','s','t','u','f','x','ts','ch','sh','shch','`','y','\'','è','yu','ya','A','B','V','G','D','E','ZH','Z','I','J','K','L','M','N','O','P','R','S','T','U','F','X','TS','CH','SH','SHCH','`','Y','\'','È','YU','YA'];
for (i=0; i<alfRus.length; i++) {
var letra = alfRus[i];
var re = new RegExp(letra, "g");
txt = txt.replace(re,equivRus[i]);
}
txt = txt.substring(0,1).toUpperCase() + txt.substring(1,txt.length);
return txt;
}
function transcribirGri(txt) {
var alfGri = ['ά','έ','ή','ί','ΰ','α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','ς','σ','τ','υ','φ','χ','ψ','ω','ϊ','ϋ','ό','ύ','ώ', 'Ή','Ί','Ό','Ύ','Ώ','ΐ','Α','Β','Γ','Δ','Ε','Ζ','Η','Θ','Ι','Κ','Λ','Μ','Ν','Ξ','Ο','Π','Ρ','Σ','Τ','Υ','Φ','Χ','Ψ','Ω','Ϊ','Ϋ'];
var equivGri = ['á','é','ì','í','ü','a','v','g','d','e','z','ī','th','i','k','l','m','n','x','o','p','r','s','s','t','u','f','kh','ps','ō','ï','ü','ó','ú','ò','Ì','Í','Ó','Ú','Ò','Ï','A','V','G','D','E','Z','Ī','TH','I','K','L','M','N','X','O','P','R','S','T','U','F','KH','PS','Ō','Ï','Ü'];
for (i=0; i<alfGri.length; i++) {
var letra = alfGri[i];
var re = new RegExp(letra, "g");
txt = txt.replace(re,equivGri[i]);
}
txt = txt.substring(0,1).toUpperCase() + txt.substring(1,txt.length);
return txt;
}
function transcribirHeb(txt) {
var palsHeb = ["מנהיג המפלגה הסוציאליסטית","מתח ביקורת על","לפני שלושה ימים","לאחר שלושה ימים","הוא לבקר את","בארצות הברית","שר החוץ","חתם על","יחתום על","השתתף","את התערוכה","במרכז העיר","בשבוע שעבר","בארמון הלאומי","בשבוע הבא","בתערוכה","בברצלונה","במדריד","במלון","ביום שני","ביום שלישי","ביום רביעי","ביום חמישי","ביום שישי","ביום ראשון","לפני רגע","את הכנס","מחרתיים","בצרפת","בשבת","מכונית","ההסכם","אתמול","שלשום","הבוקר","הערב","בכנס","יחנוך","נשיא","בסין","שופט","שחקן","יקנה","נפגש","היום","יפגש","ידבר","יתמוך","קיבל","יקבל","בית","מחר","מלך","זמר","חנך","קנה","דיבר","תמך","מת","את","עם","ה","ב"];
var equivHeb = ["manhig ha-miflagah ha-sotzi'alistit","matah biqoret :al","lifney shloshah yomim","l'axar shloshah yomim","ho' lebiqer 'et","ba-'artzot habrit","shar ha-xutz","xatam :al","yitxom :al","hishtatef","'et ha-ta:aruxah","b-merkaz ha-:ir","ba-shabu:a she-:abar","ba-'armon ha-l'umi","ba-shabu:a haba'","ba-ta:aruxah","b-bartzelonah","b-madrid","b-malon","ba-yom sheni","ba-yom shlishi","ba-yom rbi:i","ba-yom xamishi","ba-yom shishi","ba-yom ri'shon","lifney regah","'et ha-kenes","maxareteyim","b-tzarfat","b-shabat","mxonit","ha-heskem","'etmol","shilshom","ha-boqer","ha-:ereb","ba-kenes","yixnox","nasi'","b-sin","shofet","shaxqan","yiqneh","nifgash","ha-yom","yipagesh","yedaber","yitmox","qibel","yeqabel","bayt","maxar","melex","zammar","xanax","qanah","diber","tamax","met","'et",":im","ha-","ba-"];
for (i=0; i<palsHeb.length; i++) {
var pal = palsHeb[i];
var re = new RegExp(pal, "g");
txt = txt.replace(re,equivHeb[i]);
}
return txt;
}
function transcribirAra(txt) {
var palsAra = ["زعيم الحزب الاشتراكي","وزير الخارجية","قبل ثلاثة أيام","بعد ثلاثة أيام","في مركز المدينة","في الولايات المتحدة","في القصر الوطني","قد ينتقد","على الاتفاق","يوم الإثنين","يوم الثلاثاء","يوم الاربعاء","يوم الخميس","يوم الجمعة","يوم السبت","يوم الأحد","لأسبوع القادم","الإسبوع الماضي","هذا المساء","هذا الصباح","في برشلونة","في مدريد","في فرنسا","في فندق","في الصين","أمس الأول","منذ لحظة","سيتحدث","سيفتتح","افتتح","سيشتري","سيلتقي","سيستقبل","بعد غد","المؤتمر","المعرض","الممثل","إستقبل","المغني","الرئيس","الملك","سيحضر","انتقد","سيوقع","القاضي","اشترى","سيارة","اليوم","توفي","التقى","سيؤيد","تحدث","منزلا","بيتا","أيد","وقع","حضر","غداً","أمس","مع","ب"];
var equivAra = ["za:īm al-Hizbi l-'ištirākiyy","wazīr al-xāriǧiyya","qabla thalathati 'ayyām","ba:da thalathati 'ayyām","fī markazi l-madīna","fī l-wilāyāti l-mutaHida","fī l-qaSri l-waTaniyy","qad yantaqidu",":alà l-'ittifāq","yawma l-'ithnayn","yawma th-thulāthā'","yawma l-'arbi:ā'","yawma l-xamīs","yawma l-ǧum:a","yawma s-sabt","yawma -l'aHad","al-'usbū:a l-qādim","al-'usbū:a l-māDī","hadhā l-masā'","hadhā S-Sabāh","fī baršilūna","fī madrīd","fī faransā","fī funduq","fī S-Sīn","'amsi l-'awwal","mundhu laHZa","sa-yataHaddathu","sa-yaftatiHu","iftataHa","sa-yaštarī","sa-yaltaqī","sa-yastaqbilu","ba:da gad","al-mu'tamar","al-ma:riD","al-mumaththil","istaqbala","al-mugannī","ar-ra'īs","al-malik","sa-yaHDuru","intaqada","sa-yuwaqqi:u","al-qaDī","ištarà","sayyāra","al-yawma","tawaffī","iltaqà","sa-yu'ayyidu","taHaddatha","manzilän","baytän","'ayyada","waqqa:a","HaDara","gadän","'amsi","ma:a","bi-"];
for (i=0; i<palsAra.length; i++) {
var pal = palsAra[i];
var re = new RegExp(pal, "g");
txt = txt.replace(re,equivAra[i]);
}
return txt;
}
function transcribirHin(txt) {
var palsHin = ["समाजवादी पार्टी के नेता","का समर्थन किया","का स्वागत किया","का स्वागत करेगा","का समर्थन करेगा","की आलोचना की","की आलोचना कर सख्ता है","एक क्षण पहले","तीन दिन पहले","तीन दिन में","हस्ताक्षर किए","हस्ताक्षर करने","समझौते पर","समझौता","न्यायाधीश","अभिनेता","अगले हफ़्ते","पिछले हफ़्ते","राष्ट्रीय पैलेस मे","विदेश मंत्री","प्रदर्शनी","सम्मेलन","राष्ट्रपति","शहर के केंद्र में","मर गया","मैड्रिड में","अमेरीका में","बार्सिलोना में","एक होटल में","आज सुबह","आज शाम","फ्रांस में","चीन में","सोमवार","मंगलवार","बुधवार","गुरुवार","शुक्रवार","शनिवार","रविवार","ख़रीदेगा","ख़रीदेगी","परसों","खरीदा","ख़रीदी","राजा","गायक","खोलेगा","खोलेगी","खोला","खोली","मिलेगा","मिलेगी","मिला","मिली","बोलेगा","बोलेगी","बोला","बोली","जाएगा","जाएगी","गया","गई","गाड़ी","घर","आज","कल","पर","को","ने","से","है"];
var equivHin = ["samájavádí parti ke netá","ká samarTan kiyá","ká svágat kiyá","ká svágat karegá","ká samarTan karegá","kí alocná kí","kí alocná kar sakhtá hai","ek kshaN pahle","tín din pahle","tín din mê","hastashkar kie","hastashkar karegá","samajhaute par","samajhautá","nyáyádhísh","abhinetá","agle hafte","pichle hafte","rastriy pailes mê","videsh mantrí","pradarshaní","sammelan","raStrapti","shahar ke kendr mê","mer gayá","maDriD mê","ameriká mê","bársiloná mê","ek hoTal mê","áj subah","áj shám","phrans mê","cín mê","somvár","manglavár","budhvár","guruvár","shukravár","shanivár","ravivár","xaridegá","xaridegí","parsô","xaridá","xaridí","rájá","gáyak","kholegá","kholegí","kholá","kholí","milegá","milegí","milá","milí","bolegá","bolegí","bolá","bolí","jaegá","jaegí","gayá","gaí","gaRHí","ghar","áj","kal","par","ko","ne","se","hai"];
for (i=0; i<palsHin.length; i++) {
var pal = palsHin[i];
var re = new RegExp(pal, "g");
txt = txt.replace(re,equivHin[i]);
}
return txt;
}
function transcribirChi(txt) {
var palsChi = ["社会党领袖","在巴塞罗那","一套房子","在国家宫","在市中心","今天上午","今天晚上","下个星期","在马德里","在法国","在中国","在美国","在饭店","星期一","星期二","星期三","星期四","星期五","星期六","星期日","星期天","上星期","外交部","见了面","说了话","展览会","一辆车","三天前","在三天","刚才","今天","昨天","前天","后天","国王","明天","总统","法官","歌手","演员","开幕","购买","死了","见面","说话","支持","收到","批评","出席","会议","协议","签","上","下","跟","与","要","了"];
var equivChi = ["shèhuì-dǎng lǐngxiù","zài bāsèluōnà","yī tào fángzi","zài guójiā-gōng","zài shì zhōngxīn","jīntiān shàngwǔ","jīntiān wǎnshàng","xiàge xīngqí","zài mǎdélǐ","zài fàguó","zài zhōngguó","zài měiguó","zài fàndiàn","xīngqíyī","xīngqí'èr","xīngqísān","xīngqísì","xīngqíwǔ","xīngqíliù","xīngqírì","xīngqítiān","shàng xīngqí","wàijiāo bù","jiàn-le-miàn","shuō-le-huà","zhǎnlànhuì","yī liàng chē","sān tiān qián","zài sān tiān","gāngcái","jīntiān","zuótiān","qiántiān","hòutiān","guówáng","míngtiān","zǒngtǒng","fǎguān","gēshǒu","yǎnyuán","kāimù","gòumǎi","sǐ le","jiànmiàn","shuōhuà","zhīchí","shōudào","pīpíng","chūxí","huìyì","xiéyì","qiān","shàng ","xià ","gēn","yǔ","yào","le"];
for (i=0; i<palsChi.length; i++) {
var pal = palsChi[i];
var re = new RegExp(pal, "g");
txt = txt.replace(re,equivChi[i]);
}
return txt;
}
function decir(idioma, txt) {
voices = synth.getVoices();
var u = new SpeechSynthesisUtterance(txt);
u.rate = 1.3;
for (i=0;i<voices.length;i++) {
if (voices[i].lang == idioma) {
u.voice = voices[i];
break;
}
}
synth.speak(u);
}
</script>
</head>
<body>
<div id="todo">
<div id="cabecera">
<div id="cabeceraTitulo">MULTILINGUAL HEADLINES GENERATOR</div>
<div class="cabeceraExplicacion">Click <span id="botonGenerar" onclick="getInfo()">here</span> or press the 'f' key in your keyboard to generate a headline</div>
<div id="cabeceraCreditos">Made by <a href="https://twitter.com/joseprzmoreno">me</a> with <a href="http://www.grammaticalframework.org/">Grammatical Framework</a> and the <a href="https://code.google.com/archive/p/grammatical-framework/wikis/GFWebServiceAPI.wiki">Grammatical Framework Web Service API</a>. (Hopefully,) to be improved in the future.</div>
</div>
<div id="contTitulares">
<img id="imagenPeriodicos" src="https://www.dropbox.com/s/g4zmwks582w3usa/periodicos.png?raw=1"></img>
</div>
</div>
</body>
</html>