added dropdown box for subscribe
[squirrelmail.git] / functions / i18n.php
CommitLineData
1fd97780 1<?
2
3/**
4 ** i18n.php
5 **
6 ** This file contains variuos functions that are needed to do
7 ** internationalization of SquirrelMail.
8 **
9 ** Internally iso-8859-1 is used as character set. Other characters
10 ** are encoded using Unicode entities according to HTML 4.0.
173ed887 11 **
1fd97780 12 **/
13
14 $i18n_php = true;
15
d30d79f2 16 // This array specifies the available languages.
e8816411 17 $languages["en"]["NAME"] = "English";
18 $languages["no"]["NAME"] = "Norsk";
19 $languages["no"]["CHARSET"] = "iso-8859-1";
20 $languages["de"]["NAME"] = "Deutcsh";
21 $languages["de"]["CHARSET"] = "iso-8859-1";
22 $languages["ru"]["NAME"] = "Russian KOI8-R";
23 $languages["ru"]["CHARSET"] = "koi8-r";
d30d79f2 24
1fd97780 25 // Decodes a string to the internal encoding from the given charset
26 function charset_decode ($charset, $string) {
27 // All HTML special characters are 7 bit and can be replaced first
28 $string = htmlspecialchars ($string);
29
44139266 30 $charset = strtolower($charset);
1fd97780 31
32 if (ereg("iso-8859-(.*)", $charset, $res)) {
33 if ($res[1] == "1")
34 return charset_decode_iso_8859_1 ($string);
173ed887 35 if ($res[1] == "7")
36 return charset_decode_iso_8859_7 ($string);
1fd97780 37 else if ($res[1] == "15")
38 return charset_decode_iso_8859_15 ($string);
39 else
40 return charset_decode_iso_8859_default ($string);
41 } else if ($charset == "ns_4551-1") {
42 return charset_decode_ns_4551_1 ($string);
17ce8467 43 } else if ($charset == "koi8-r") {
44 return charset_decode_koi8r ($string);
209e2f82 45 } else
8c5a2cb2 46 return "$string";
1fd97780 47 }
48
49 // iso-8859-1 is the same as Latin 1 and is normally used
50 // in western europe.
51 function charset_decode_iso_8859_1 ($string) {
04563822 52 global $default_charset;
1fd97780 53
04563822 54 if (strtolower($default_charset) == "iso-8859-1") {
55 return $string;
56 } else {
57 // Only do the slow convert if there are 8-bit characters
58 if (ereg("[\200-\377]", $string)) {
59 $string = str_replace("\201", "&#129;", $string);
60 $string = str_replace("\202", "&#130;", $string);
61 $string = str_replace("\203", "&#131;", $string);
62 $string = str_replace("\204", "&#132;", $string);
63 $string = str_replace("\205", "&#133;", $string);
64 $string = str_replace("\206", "&#134;", $string);
65 $string = str_replace("\207", "&#135;", $string);
66 $string = str_replace("\210", "&#136;", $string);
67 $string = str_replace("\211", "&#137;", $string);
68 $string = str_replace("\212", "&#138;", $string);
69 $string = str_replace("\213", "&#139;", $string);
70 $string = str_replace("\214", "&#140;", $string);
71 $string = str_replace("\215", "&#141;", $string);
72 $string = str_replace("\216", "&#142;", $string);
73 $string = str_replace("\217", "&#143;", $string);
74 $string = str_replace("\220", "&#144;", $string);
75 $string = str_replace("\221", "&#145;", $string);
76 $string = str_replace("\222", "&#146;", $string);
77 $string = str_replace("\223", "&#147;", $string);
78 $string = str_replace("\224", "&#148;", $string);
79 $string = str_replace("\225", "&#149;", $string);
80 $string = str_replace("\226", "&#150;", $string);
81 $string = str_replace("\227", "&#151;", $string);
82 $string = str_replace("\230", "&#152;", $string);
83 $string = str_replace("\231", "&#153;", $string);
84 $string = str_replace("\232", "&#154;", $string);
85 $string = str_replace("\233", "&#155;", $string);
86 $string = str_replace("\234", "&#156;", $string);
87 $string = str_replace("\235", "&#157;", $string);
88 $string = str_replace("\236", "&#158;", $string);
89 $string = str_replace("\237", "&#159;", $string);
90 $string = str_replace("\240", "&#160;", $string);
91 $string = str_replace("\241", "&#161;", $string);
92 $string = str_replace("\242", "&#162;", $string);
93 $string = str_replace("\243", "&#163;", $string);
94 $string = str_replace("\244", "&#164;", $string);
95 $string = str_replace("\245", "&#165;", $string);
96 $string = str_replace("\246", "&#166;", $string);
97 $string = str_replace("\247", "&#167;", $string);
98 $string = str_replace("\250", "&#168;", $string);
99 $string = str_replace("\251", "&#169;", $string);
100 $string = str_replace("\252", "&#170;", $string);
101 $string = str_replace("\253", "&#171;", $string);
102 $string = str_replace("\254", "&#172;", $string);
103 $string = str_replace("\255", "&#173;", $string);
104 $string = str_replace("\256", "&#174;", $string);
105 $string = str_replace("\257", "&#175;", $string);
106 $string = str_replace("\260", "&#176;", $string);
107 $string = str_replace("\261", "&#177;", $string);
108 $string = str_replace("\262", "&#178;", $string);
109 $string = str_replace("\263", "&#179;", $string);
110 $string = str_replace("\264", "&#180;", $string);
111 $string = str_replace("\265", "&#181;", $string);
112 $string = str_replace("\266", "&#182;", $string);
113 $string = str_replace("\267", "&#183;", $string);
114 $string = str_replace("\270", "&#184;", $string);
115 $string = str_replace("\271", "&#185;", $string);
116 $string = str_replace("\272", "&#186;", $string);
117 $string = str_replace("\273", "&#187;", $string);
118 $string = str_replace("\274", "&#188;", $string);
119 $string = str_replace("\275", "&#189;", $string);
120 $string = str_replace("\276", "&#190;", $string);
121 $string = str_replace("\277", "&#191;", $string);
122 $string = str_replace("\300", "&#192;", $string);
123 $string = str_replace("\301", "&#193;", $string);
124 $string = str_replace("\302", "&#194;", $string);
125 $string = str_replace("\303", "&#195;", $string);
126 $string = str_replace("\304", "&#196;", $string);
127 $string = str_replace("\305", "&#197;", $string);
128 $string = str_replace("\306", "&#198;", $string);
129 $string = str_replace("\307", "&#199;", $string);
130 $string = str_replace("\310", "&#200;", $string);
131 $string = str_replace("\311", "&#201;", $string);
132 $string = str_replace("\312", "&#202;", $string);
133 $string = str_replace("\313", "&#203;", $string);
134 $string = str_replace("\314", "&#204;", $string);
135 $string = str_replace("\315", "&#205;", $string);
136 $string = str_replace("\316", "&#206;", $string);
137 $string = str_replace("\317", "&#207;", $string);
138 $string = str_replace("\320", "&#208;", $string);
139 $string = str_replace("\321", "&#209;", $string);
140 $string = str_replace("\322", "&#210;", $string);
141 $string = str_replace("\323", "&#211;", $string);
142 $string = str_replace("\324", "&#212;", $string);
143 $string = str_replace("\325", "&#213;", $string);
144 $string = str_replace("\326", "&#214;", $string);
145 $string = str_replace("\327", "&#215;", $string);
146 $string = str_replace("\330", "&#216;", $string);
147 $string = str_replace("\331", "&#217;", $string);
148 $string = str_replace("\332", "&#218;", $string);
149 $string = str_replace("\333", "&#219;", $string);
150 $string = str_replace("\334", "&#220;", $string);
151 $string = str_replace("\335", "&#221;", $string);
152 $string = str_replace("\336", "&#222;", $string);
153 $string = str_replace("\337", "&#223;", $string);
154 $string = str_replace("\340", "&#224;", $string);
155 $string = str_replace("\341", "&#225;", $string);
156 $string = str_replace("\342", "&#226;", $string);
157 $string = str_replace("\343", "&#227;", $string);
158 $string = str_replace("\344", "&#228;", $string);
159 $string = str_replace("\345", "&#229;", $string);
160 $string = str_replace("\346", "&#230;", $string);
161 $string = str_replace("\347", "&#231;", $string);
162 $string = str_replace("\350", "&#232;", $string);
163 $string = str_replace("\351", "&#233;", $string);
164 $string = str_replace("\352", "&#234;", $string);
165 $string = str_replace("\353", "&#235;", $string);
166 $string = str_replace("\354", "&#236;", $string);
167 $string = str_replace("\355", "&#237;", $string);
168 $string = str_replace("\356", "&#238;", $string);
169 $string = str_replace("\357", "&#239;", $string);
170 $string = str_replace("\360", "&#240;", $string);
171 $string = str_replace("\361", "&#241;", $string);
172 $string = str_replace("\362", "&#242;", $string);
173 $string = str_replace("\363", "&#243;", $string);
174 $string = str_replace("\364", "&#244;", $string);
175 $string = str_replace("\365", "&#245;", $string);
176 $string = str_replace("\366", "&#246;", $string);
177 $string = str_replace("\367", "&#247;", $string);
178 $string = str_replace("\370", "&#248;", $string);
179 $string = str_replace("\371", "&#249;", $string);
180 $string = str_replace("\372", "&#250;", $string);
181 $string = str_replace("\373", "&#251;", $string);
182 $string = str_replace("\374", "&#252;", $string);
183 $string = str_replace("\375", "&#253;", $string);
184 $string = str_replace("\376", "&#254;", $string);
185 $string = str_replace("\377", "&#255;", $string);
186 }
187 }
1fd97780 188
189 return ($string);
190 }
191
0a86e9f3 192 // iso-8859-7 is Greek.
209e2f82 193 function charset_decode_iso_8859_7 ($string) {
04563822 194 global $default_charset;
173ed887 195
04563822 196 if (strtolower($default_charset) == "iso-8859-7") {
197 return $string;
198 } else {
199 // Only do the slow convert if there are 8-bit characters
200 if (ereg("[\200-\377]", $string)) {
201 // Some diverse characters in the beginning
202 $string = str_replace("\240", "&#160;", $string);
203 $string = str_replace("\241", "&#8216;", $string);
204 $string = str_replace("\242", "&#8217;", $string);
205 $string = str_replace("\243", "&#163;", $string);
206 $string = str_replace("\246", "&#166;", $string);
207 $string = str_replace("\247", "&#167;", $string);
208 $string = str_replace("\250", "&#168;", $string);
209 $string = str_replace("\251", "&#169;", $string);
210 $string = str_replace("\253", "&#171;", $string);
211 $string = str_replace("\254", "&#172;", $string);
212 $string = str_replace("\255", "&#173;", $string);
213 $string = str_replace("\257", "&#8213;", $string);
214 $string = str_replace("\260", "&#176;", $string);
215 $string = str_replace("\261", "&#177;", $string);
216 $string = str_replace("\262", "&#178;", $string);
217 $string = str_replace("\263", "&#179;", $string);
218
219 // Horizontal bar (parentheki pavla)
220 $string = str_replace ("\257", "&#8213;", $string);
221
222 // ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
223 // These are Unicode 900-902
224 while (ereg("([\264-\266])", $string, $res)) {
225 $replace = "&#" . (ord($res[1])+720) . ";";
226 $string = str_replace($res[1], $replace, $string);
227 }
228
229 // 11/07 (0xB7) Middle dot is the same in iso-8859-1
230 $string = str_replace("\267", "&#183;", $string);
231
232 // ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
233 // These are Unicode 900-902
234 while (ereg("([\270-\272])", $string, $res)) {
235 $replace = "&#" . (ord($res[1])+720) . ";";
236 $string = str_replace($res[1], $replace, $string);
237 }
238
239 // 11/11 (0xBB) Right angle quotation mark is the same as in
240 // iso-8859-1
241 $string = str_replace("\273", "&#187;", $string);
242
243 // And now the rest of the charset
244 while (ereg("([\274-\376])", $string, $res)) {
245 $replace = "&#" . (ord($res[1])+720) . ";";
246 $string = str_replace($res[1], $replace, $string);
247 }
248 }
173ed887 249 }
250
251 return $string;
252 }
253
1fd97780 254 // iso-8859-15 is Latin 15 and has very much the same use as Latin 1
255 // but has the Euro symbol and some characters needed for French.
256 function charset_decode_iso_8859_15 ($string) {
257 // Euro sign
d23e472b 258 $string = str_replace ("\244", "&#8364;", $string);
1fd97780 259 // Latin capital letter S with caron
d23e472b 260 $string = str_replace ("\244", "&#352;", $string);
1fd97780 261 // Latin small letter s with caron
d23e472b 262 $string = str_replace ("\250", "&#353;", $string);
1fd97780 263 // Latin capital letter Z with caron
d23e472b 264 $string = str_replace ("\264", "&#381;", $string);
1fd97780 265 // Latin small letter z with caron
d23e472b 266 $string = str_replace ("\270", "&#382;", $string);
1fd97780 267 // Latin capital ligature OE
d23e472b 268 $string = str_replace ("\274", "&#338;", $string);
1fd97780 269 // Latin small ligature oe
d23e472b 270 $string = str_replace ("\275", "&#339;", $string);
1fd97780 271 // Latin capital letter Y with diaeresis
d23e472b 272 $string = str_replace ("\276", "&#376;", $string);
1fd97780 273
04563822 274 return (charset_decode_iso_8859_1($string));
1fd97780 275 }
276
17ce8467 277 // ISO-8859-15 is Cyrillic
278 function charset_decode_iso_8859_5 ($string) {
d23e472b 279 // Convert to KOI8-R, then return this decoded.
280 $string = convert_cyr_string($string, "i", "k");
281 return charset_decode_koi8r($string);
17ce8467 282 }
283
173ed887 284 // Remove all 8 bit characters from all other ISO-8859 character sets
1fd97780 285 function charset_decode_iso_8859_default ($string) {
286 return (strtr($string, "\240\241\242\243\244\245\246\247".
287 "\250\251\252\253\254\255\256\257".
288 "\260\261\262\263\264\265\266\267".
289 "\270\271\272\273\274\275\276\277".
290 "\300\301\302\303\304\305\306\307".
291 "\310\311\312\313\314\315\316\317".
292 "\320\321\322\323\324\325\326\327".
293 "\330\331\332\333\334\335\336\337".
294 "\340\341\342\343\344\345\346\347".
295 "\350\351\352\353\354\355\356\357".
296 "\360\361\362\363\364\365\366\367".
297 "\370\371\372\373\374\375\376\377",
298 "????????????????????????????????????????".
299 "????????????????????????????????????????".
300 "????????????????????????????????????????".
301 "????????"));
302
303 }
304
305 // This is the same as ISO-646-NO and is used by some
306 // Microsoft programs when sending Norwegian characters
307 function charset_decode_ns_4551_1 ($string) {
308 // These characters are:
309 // Latin capital letter AE
310 // Latin capital letter O with stroke
311 // Latin capital letter A with ring above
312 // and the same as small letters
313 return strtr ($string, "[\\]{|}", "");
314 }
315
17ce8467 316 // KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
317 // 1489.
318 function charset_decode_koi8r ($string) {
319 global $default_charset;
320
321 if ($default_charset == "koi8-r") {
322 return $string;
323 } else {
324 // Convert to Unicode HTML entities.
325 // This code is rather ineffective.
d23e472b 326 $string = str_replace("\200", "&#9472;", $string);
327 $string = str_replace("\201", "&#9474;", $string);
328 $string = str_replace("\202", "&#9484;", $string);
329 $string = str_replace("\203", "&#9488;", $string);
330 $string = str_replace("\204", "&#9492;", $string);
331 $string = str_replace("\205", "&#9496;", $string);
332 $string = str_replace("\206", "&#9500;", $string);
333 $string = str_replace("\207", "&#9508;", $string);
334 $string = str_replace("\210", "&#9516;", $string);
335 $string = str_replace("\211", "&#9524;", $string);
336 $string = str_replace("\212", "&#9532;", $string);
337 $string = str_replace("\213", "&#9600;", $string);
338 $string = str_replace("\214", "&#9604;", $string);
339 $string = str_replace("\215", "&#9608;", $string);
340 $string = str_replace("\216", "&#9612;", $string);
341 $string = str_replace("\217", "&#9616;", $string);
342 $string = str_replace("\220", "&#9617;", $string);
343 $string = str_replace("\221", "&#9618;", $string);
344 $string = str_replace("\222", "&#9619;", $string);
345 $string = str_replace("\223", "&#8992;", $string);
346 $string = str_replace("\224", "&#9632;", $string);
347 $string = str_replace("\225", "&#8729;", $string);
348 $string = str_replace("\226", "&#8730;", $string);
349 $string = str_replace("\227", "&#8776;", $string);
350 $string = str_replace("\230", "&#8804;", $string);
351 $string = str_replace("\231", "&#8805;", $string);
352 $string = str_replace("\232", "&#160;", $string);
353 $string = str_replace("\233", "&#8993;", $string);
354 $string = str_replace("\234", "&#176;", $string);
355 $string = str_replace("\235", "&#178;", $string);
356 $string = str_replace("\236", "&#183;", $string);
357 $string = str_replace("\237", "&#247;", $string);
358 $string = str_replace("\240", "&#9552;", $string);
359 $string = str_replace("\241", "&#9553;", $string);
360 $string = str_replace("\242", "&#9554;", $string);
361 $string = str_replace("\243", "&#1105;", $string);
362 $string = str_replace("\244", "&#9555;", $string);
363 $string = str_replace("\245", "&#9556;", $string);
364 $string = str_replace("\246", "&#9557;", $string);
365 $string = str_replace("\247", "&#9558;", $string);
366 $string = str_replace("\250", "&#9559;", $string);
367 $string = str_replace("\251", "&#9560;", $string);
368 $string = str_replace("\252", "&#9561;", $string);
369 $string = str_replace("\253", "&#9562;", $string);
370 $string = str_replace("\254", "&#9563;", $string);
371 $string = str_replace("\255", "&#9564;", $string);
372 $string = str_replace("\256", "&#9565;", $string);
373 $string = str_replace("\257", "&#9566;", $string);
374 $string = str_replace("\260", "&#9567;", $string);
375 $string = str_replace("\261", "&#9568;", $string);
376 $string = str_replace("\262", "&#9569;", $string);
377 $string = str_replace("\263", "&#1025;", $string);
378 $string = str_replace("\264", "&#9570;", $string);
379 $string = str_replace("\265", "&#9571;", $string);
380 $string = str_replace("\266", "&#9572;", $string);
381 $string = str_replace("\267", "&#9573;", $string);
382 $string = str_replace("\270", "&#9574;", $string);
383 $string = str_replace("\271", "&#9575;", $string);
384 $string = str_replace("\272", "&#9576;", $string);
385 $string = str_replace("\273", "&#9577;", $string);
386 $string = str_replace("\274", "&#9578;", $string);
387 $string = str_replace("\275", "&#9579;", $string);
388 $string = str_replace("\276", "&#9580;", $string);
389 $string = str_replace("\277", "&#169;", $string);
390 $string = str_replace("\300", "&#1102;", $string);
391 $string = str_replace("\301", "&#1072;", $string);
392 $string = str_replace("\302", "&#1073;", $string);
393 $string = str_replace("\303", "&#1094;", $string);
394 $string = str_replace("\304", "&#1076;", $string);
395 $string = str_replace("\305", "&#1077;", $string);
396 $string = str_replace("\306", "&#1092;", $string);
397 $string = str_replace("\307", "&#1075;", $string);
398 $string = str_replace("\310", "&#1093;", $string);
399 $string = str_replace("\311", "&#1080;", $string);
400 $string = str_replace("\312", "&#1081;", $string);
401 $string = str_replace("\313", "&#1082;", $string);
402 $string = str_replace("\314", "&#1083;", $string);
403 $string = str_replace("\315", "&#1084;", $string);
404 $string = str_replace("\316", "&#1085;", $string);
405 $string = str_replace("\317", "&#1086;", $string);
406 $string = str_replace("\320", "&#1087;", $string);
407 $string = str_replace("\321", "&#1103;", $string);
408 $string = str_replace("\322", "&#1088;", $string);
409 $string = str_replace("\323", "&#1089;", $string);
410 $string = str_replace("\324", "&#1090;", $string);
411 $string = str_replace("\325", "&#1091;", $string);
412 $string = str_replace("\326", "&#1078;", $string);
413 $string = str_replace("\327", "&#1074;", $string);
414 $string = str_replace("\330", "&#1100;", $string);
415 $string = str_replace("\331", "&#1099;", $string);
416 $string = str_replace("\332", "&#1079;", $string);
417 $string = str_replace("\333", "&#1096;", $string);
418 $string = str_replace("\334", "&#1101;", $string);
419 $string = str_replace("\335", "&#1097;", $string);
420 $string = str_replace("\336", "&#1095;", $string);
421 $string = str_replace("\337", "&#1098;", $string);
422 $string = str_replace("\340", "&#1070;", $string);
423 $string = str_replace("\341", "&#1040;", $string);
424 $string = str_replace("\342", "&#1041;", $string);
425 $string = str_replace("\343", "&#1062;", $string);
426 $string = str_replace("\344", "&#1044;", $string);
427 $string = str_replace("\345", "&#1045;", $string);
428 $string = str_replace("\346", "&#1060;", $string);
429 $string = str_replace("\347", "&#1043;", $string);
430 $string = str_replace("\350", "&#1061;", $string);
431 $string = str_replace("\351", "&#1048;", $string);
432 $string = str_replace("\352", "&#1049;", $string);
433 $string = str_replace("\353", "&#1050;", $string);
434 $string = str_replace("\354", "&#1051;", $string);
435 $string = str_replace("\355", "&#1052;", $string);
436 $string = str_replace("\356", "&#1053;", $string);
437 $string = str_replace("\357", "&#1054;", $string);
438 $string = str_replace("\360", "&#1055;", $string);
439 $string = str_replace("\361", "&#1071;", $string);
440 $string = str_replace("\362", "&#1056;", $string);
441 $string = str_replace("\363", "&#1057;", $string);
442 $string = str_replace("\364", "&#1058;", $string);
443 $string = str_replace("\365", "&#1059;", $string);
444 $string = str_replace("\366", "&#1046;", $string);
445 $string = str_replace("\367", "&#1042;", $string);
446 $string = str_replace("\370", "&#1068;", $string);
447 $string = str_replace("\371", "&#1067;", $string);
448 $string = str_replace("\372", "&#1047;", $string);
449 $string = str_replace("\373", "&#1064;", $string);
450 $string = str_replace("\374", "&#1069;", $string);
451 $string = str_replace("\375", "&#1065;", $string);
452 $string = str_replace("\376", "&#1063;", $string);
453 $string = str_replace("\377", "&#1066;", $string);
17ce8467 454
455 return $string;
456 }
457 }
458
1fd97780 459?>