aaf14d432c2f17f11e33f2a184df6680ece494ed
6 ** This file contains variuos functions that are needed to do
7 ** internationalization of SquirrelMail.
9 ** Internally the output character set is used. Other characters are
10 ** encoded using Unicode entities according to HTML 4.0.
16 // This array specifies the available languages.
17 $languages["en"]["NAME"] = "English";
18 $languages["no"]["NAME"] = "Norsk";
19 $languages["no"]["CHARSET"] = "iso-8859-1";
20 $languages["de"]["NAME"] = "Deutsch";
21 $languages["de"]["CHARSET"] = "iso-8859-1";
22 $languages["ru"]["NAME"] = "Russian KOI8-R";
23 $languages["ru"]["CHARSET"] = "koi8-r";
24 $languages["pl"]["NAME"] = "Polish";
25 $languages["pl"]["CHARSET"] = "iso-8859-2";
26 $languages["sv"]["NAME"] = "Swedish";
27 $languages["sv"]["CHARSET"] = "iso-8859-1";
28 $languages["nl"]["NAME"] = "Dutch";
29 $languages["nl"]["CHARSET"] = "iso-8859-1";
30 $languages["pt_BR"]["NAME"] = "Portuguese (Brazil)";
31 $languages["pt_BR"]["CHARSET"] = "iso-8859-1";
32 $languages["fr"]["NAME"] = "French";
33 $languages["fr"]["CHARSET"] = "iso-8859-1";
35 // Decodes a string to the internal encoding from the given charset
36 function charset_decode ($charset, $string) {
39 // All HTML special characters are 7 bit and can be replaced first
40 $string = htmlspecialchars ($string);
42 $charset = strtolower($charset);
44 if ($debug_mime) $string = $charset.":".$string;
46 if (ereg("iso-8859-(.*)", $charset, $res)) {
48 return charset_decode_iso_8859_1 ($string);
50 return charset_decode_iso_8859_7 ($string);
51 else if ($res[1] == "15")
52 return charset_decode_iso_8859_15 ($string);
54 return charset_decode_iso_8859_default ($string);
55 } else if ($charset == "ns_4551-1") {
56 return charset_decode_ns_4551_1 ($string);
57 } else if ($charset == "koi8-r") {
58 return charset_decode_koi8r ($string);
63 // iso-8859-1 is the same as Latin 1 and is normally used
65 function charset_decode_iso_8859_1 ($string) {
66 global $default_charset;
68 if (strtolower($default_charset) == "iso-8859-1") {
71 // Only do the slow convert if there are 8-bit characters
72 if (ereg("[\200-\377]", $string)) {
73 $string = str_replace("\201", "", $string);
74 $string = str_replace("\202", "‚", $string);
75 $string = str_replace("\203", "ƒ", $string);
76 $string = str_replace("\204", "„", $string);
77 $string = str_replace("\205", "…", $string);
78 $string = str_replace("\206", "†", $string);
79 $string = str_replace("\207", "‡", $string);
80 $string = str_replace("\210", "ˆ", $string);
81 $string = str_replace("\211", "‰", $string);
82 $string = str_replace("\212", "Š", $string);
83 $string = str_replace("\213", "‹", $string);
84 $string = str_replace("\214", "Œ", $string);
85 $string = str_replace("\215", "", $string);
86 $string = str_replace("\216", "Ž", $string);
87 $string = str_replace("\217", "", $string);
88 $string = str_replace("\220", "", $string);
89 $string = str_replace("\221", "‘", $string);
90 $string = str_replace("\222", "’", $string);
91 $string = str_replace("\223", "“", $string);
92 $string = str_replace("\224", "”", $string);
93 $string = str_replace("\225", "•", $string);
94 $string = str_replace("\226", "–", $string);
95 $string = str_replace("\227", "—", $string);
96 $string = str_replace("\230", "˜", $string);
97 $string = str_replace("\231", "™", $string);
98 $string = str_replace("\232", "š", $string);
99 $string = str_replace("\233", "›", $string);
100 $string = str_replace("\234", "œ", $string);
101 $string = str_replace("\235", "", $string);
102 $string = str_replace("\236", "ž", $string);
103 $string = str_replace("\237", "Ÿ", $string);
104 $string = str_replace("\240", " ", $string);
105 $string = str_replace("\241", "¡", $string);
106 $string = str_replace("\242", "¢", $string);
107 $string = str_replace("\243", "£", $string);
108 $string = str_replace("\244", "¤", $string);
109 $string = str_replace("\245", "¥", $string);
110 $string = str_replace("\246", "¦", $string);
111 $string = str_replace("\247", "§", $string);
112 $string = str_replace("\250", "¨", $string);
113 $string = str_replace("\251", "©", $string);
114 $string = str_replace("\252", "ª", $string);
115 $string = str_replace("\253", "«", $string);
116 $string = str_replace("\254", "¬", $string);
117 $string = str_replace("\255", "­", $string);
118 $string = str_replace("\256", "®", $string);
119 $string = str_replace("\257", "¯", $string);
120 $string = str_replace("\260", "°", $string);
121 $string = str_replace("\261", "±", $string);
122 $string = str_replace("\262", "²", $string);
123 $string = str_replace("\263", "³", $string);
124 $string = str_replace("\264", "´", $string);
125 $string = str_replace("\265", "µ", $string);
126 $string = str_replace("\266", "¶", $string);
127 $string = str_replace("\267", "·", $string);
128 $string = str_replace("\270", "¸", $string);
129 $string = str_replace("\271", "¹", $string);
130 $string = str_replace("\272", "º", $string);
131 $string = str_replace("\273", "»", $string);
132 $string = str_replace("\274", "¼", $string);
133 $string = str_replace("\275", "½", $string);
134 $string = str_replace("\276", "¾", $string);
135 $string = str_replace("\277", "¿", $string);
136 $string = str_replace("\300", "À", $string);
137 $string = str_replace("\301", "Á", $string);
138 $string = str_replace("\302", "Â", $string);
139 $string = str_replace("\303", "Ã", $string);
140 $string = str_replace("\304", "Ä", $string);
141 $string = str_replace("\305", "Å", $string);
142 $string = str_replace("\306", "Æ", $string);
143 $string = str_replace("\307", "Ç", $string);
144 $string = str_replace("\310", "È", $string);
145 $string = str_replace("\311", "É", $string);
146 $string = str_replace("\312", "Ê", $string);
147 $string = str_replace("\313", "Ë", $string);
148 $string = str_replace("\314", "Ì", $string);
149 $string = str_replace("\315", "Í", $string);
150 $string = str_replace("\316", "Î", $string);
151 $string = str_replace("\317", "Ï", $string);
152 $string = str_replace("\320", "Ð", $string);
153 $string = str_replace("\321", "Ñ", $string);
154 $string = str_replace("\322", "Ò", $string);
155 $string = str_replace("\323", "Ó", $string);
156 $string = str_replace("\324", "Ô", $string);
157 $string = str_replace("\325", "Õ", $string);
158 $string = str_replace("\326", "Ö", $string);
159 $string = str_replace("\327", "×", $string);
160 $string = str_replace("\330", "Ø", $string);
161 $string = str_replace("\331", "Ù", $string);
162 $string = str_replace("\332", "Ú", $string);
163 $string = str_replace("\333", "Û", $string);
164 $string = str_replace("\334", "Ü", $string);
165 $string = str_replace("\335", "Ý", $string);
166 $string = str_replace("\336", "Þ", $string);
167 $string = str_replace("\337", "ß", $string);
168 $string = str_replace("\340", "à", $string);
169 $string = str_replace("\341", "á", $string);
170 $string = str_replace("\342", "â", $string);
171 $string = str_replace("\343", "ã", $string);
172 $string = str_replace("\344", "ä", $string);
173 $string = str_replace("\345", "å", $string);
174 $string = str_replace("\346", "æ", $string);
175 $string = str_replace("\347", "ç", $string);
176 $string = str_replace("\350", "è", $string);
177 $string = str_replace("\351", "é", $string);
178 $string = str_replace("\352", "ê", $string);
179 $string = str_replace("\353", "ë", $string);
180 $string = str_replace("\354", "ì", $string);
181 $string = str_replace("\355", "í", $string);
182 $string = str_replace("\356", "î", $string);
183 $string = str_replace("\357", "ï", $string);
184 $string = str_replace("\360", "ð", $string);
185 $string = str_replace("\361", "ñ", $string);
186 $string = str_replace("\362", "ò", $string);
187 $string = str_replace("\363", "ó", $string);
188 $string = str_replace("\364", "ô", $string);
189 $string = str_replace("\365", "õ", $string);
190 $string = str_replace("\366", "ö", $string);
191 $string = str_replace("\367", "÷", $string);
192 $string = str_replace("\370", "ø", $string);
193 $string = str_replace("\371", "ù", $string);
194 $string = str_replace("\372", "ú", $string);
195 $string = str_replace("\373", "û", $string);
196 $string = str_replace("\374", "ü", $string);
197 $string = str_replace("\375", "ý", $string);
198 $string = str_replace("\376", "þ", $string);
199 $string = str_replace("\377", "ÿ", $string);
206 // iso-8859-7 is Greek.
207 function charset_decode_iso_8859_7 ($string) {
208 global $default_charset;
210 if (strtolower($default_charset) == "iso-8859-7") {
213 // Only do the slow convert if there are 8-bit characters
214 if (ereg("[\200-\377]", $string)) {
215 // Some diverse characters in the beginning
216 $string = str_replace("\240", " ", $string);
217 $string = str_replace("\241", "‘", $string);
218 $string = str_replace("\242", "’", $string);
219 $string = str_replace("\243", "£", $string);
220 $string = str_replace("\246", "¦", $string);
221 $string = str_replace("\247", "§", $string);
222 $string = str_replace("\250", "¨", $string);
223 $string = str_replace("\251", "©", $string);
224 $string = str_replace("\253", "«", $string);
225 $string = str_replace("\254", "¬", $string);
226 $string = str_replace("\255", "­", $string);
227 $string = str_replace("\257", "―", $string);
228 $string = str_replace("\260", "°", $string);
229 $string = str_replace("\261", "±", $string);
230 $string = str_replace("\262", "²", $string);
231 $string = str_replace("\263", "³", $string);
233 // Horizontal bar (parentheki pavla)
234 $string = str_replace ("\257", "―", $string);
236 // ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
237 // These are Unicode 900-902
238 while (ereg("([\264-\266])", $string, $res)) {
239 $replace = "&#" . (ord($res[1])+
720) . ";";
240 $string = str_replace($res[1], $replace, $string);
243 // 11/07 (0xB7) Middle dot is the same in iso-8859-1
244 $string = str_replace("\267", "·", $string);
246 // ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
247 // These are Unicode 900-902
248 while (ereg("([\270-\272])", $string, $res)) {
249 $replace = "&#" . (ord($res[1])+
720) . ";";
250 $string = str_replace($res[1], $replace, $string);
253 // 11/11 (0xBB) Right angle quotation mark is the same as in
255 $string = str_replace("\273", "»", $string);
257 // And now the rest of the charset
258 while (ereg("([\274-\376])", $string, $res)) {
259 $replace = "&#" . (ord($res[1])+
720) . ";";
260 $string = str_replace($res[1], $replace, $string);
268 // iso-8859-15 is Latin 15 and has very much the same use as Latin 1
269 // but has the Euro symbol and some characters needed for French.
270 function charset_decode_iso_8859_15 ($string) {
272 $string = str_replace ("\244", "€", $string);
273 // Latin capital letter S with caron
274 $string = str_replace ("\244", "Š", $string);
275 // Latin small letter s with caron
276 $string = str_replace ("\250", "š", $string);
277 // Latin capital letter Z with caron
278 $string = str_replace ("\264", "Ž", $string);
279 // Latin small letter z with caron
280 $string = str_replace ("\270", "ž", $string);
281 // Latin capital ligature OE
282 $string = str_replace ("\274", "Œ", $string);
283 // Latin small ligature oe
284 $string = str_replace ("\275", "œ", $string);
285 // Latin capital letter Y with diaeresis
286 $string = str_replace ("\276", "Ÿ", $string);
288 return (charset_decode_iso_8859_1($string));
291 // ISO-8859-15 is Cyrillic
292 function charset_decode_iso_8859_5 ($string) {
293 // Convert to KOI8-R, then return this decoded.
294 $string = convert_cyr_string($string, "i", "k");
295 return charset_decode_koi8r($string);
298 // Remove all 8 bit characters from all other ISO-8859 character sets
299 function charset_decode_iso_8859_default ($string) {
300 return (strtr($string, "\240\241\242\243\244\245\246\247".
301 "\250\251\252\253\254\255\256\257".
302 "\260\261\262\263\264\265\266\267".
303 "\270\271\272\273\274\275\276\277".
304 "\300\301\302\303\304\305\306\307".
305 "\310\311\312\313\314\315\316\317".
306 "\320\321\322\323\324\325\326\327".
307 "\330\331\332\333\334\335\336\337".
308 "\340\341\342\343\344\345\346\347".
309 "\350\351\352\353\354\355\356\357".
310 "\360\361\362\363\364\365\366\367".
311 "\370\371\372\373\374\375\376\377",
312 "????????????????????????????????????????".
313 "????????????????????????????????????????".
314 "????????????????????????????????????????".
319 // This is the same as ISO-646-NO and is used by some
320 // Microsoft programs when sending Norwegian characters
321 function charset_decode_ns_4551_1 ($string) {
322 // These characters are:
323 // Latin capital letter AE
324 // Latin capital letter O with stroke
325 // Latin capital letter A with ring above
326 // and the same as small letters
327 return strtr ($string, "[\\]{|}", "ÆØÅæøå");
330 // KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
332 function charset_decode_koi8r ($string) {
333 global $default_charset;
335 if ($default_charset == "koi8-r") {
338 // Convert to Unicode HTML entities.
339 // This code is rather ineffective.
340 $string = str_replace("\200", "─", $string);
341 $string = str_replace("\201", "│", $string);
342 $string = str_replace("\202", "┌", $string);
343 $string = str_replace("\203", "┐", $string);
344 $string = str_replace("\204", "└", $string);
345 $string = str_replace("\205", "┘", $string);
346 $string = str_replace("\206", "├", $string);
347 $string = str_replace("\207", "┤", $string);
348 $string = str_replace("\210", "┬", $string);
349 $string = str_replace("\211", "┴", $string);
350 $string = str_replace("\212", "┼", $string);
351 $string = str_replace("\213", "▀", $string);
352 $string = str_replace("\214", "▄", $string);
353 $string = str_replace("\215", "█", $string);
354 $string = str_replace("\216", "▌", $string);
355 $string = str_replace("\217", "▐", $string);
356 $string = str_replace("\220", "░", $string);
357 $string = str_replace("\221", "▒", $string);
358 $string = str_replace("\222", "▓", $string);
359 $string = str_replace("\223", "⌠", $string);
360 $string = str_replace("\224", "■", $string);
361 $string = str_replace("\225", "∙", $string);
362 $string = str_replace("\226", "√", $string);
363 $string = str_replace("\227", "≈", $string);
364 $string = str_replace("\230", "≤", $string);
365 $string = str_replace("\231", "≥", $string);
366 $string = str_replace("\232", " ", $string);
367 $string = str_replace("\233", "⌡", $string);
368 $string = str_replace("\234", "°", $string);
369 $string = str_replace("\235", "²", $string);
370 $string = str_replace("\236", "·", $string);
371 $string = str_replace("\237", "÷", $string);
372 $string = str_replace("\240", "═", $string);
373 $string = str_replace("\241", "║", $string);
374 $string = str_replace("\242", "╒", $string);
375 $string = str_replace("\243", "ё", $string);
376 $string = str_replace("\244", "╓", $string);
377 $string = str_replace("\245", "╔", $string);
378 $string = str_replace("\246", "╕", $string);
379 $string = str_replace("\247", "╖", $string);
380 $string = str_replace("\250", "╗", $string);
381 $string = str_replace("\251", "╘", $string);
382 $string = str_replace("\252", "╙", $string);
383 $string = str_replace("\253", "╚", $string);
384 $string = str_replace("\254", "╛", $string);
385 $string = str_replace("\255", "╜", $string);
386 $string = str_replace("\256", "╝", $string);
387 $string = str_replace("\257", "╞", $string);
388 $string = str_replace("\260", "╟", $string);
389 $string = str_replace("\261", "╠", $string);
390 $string = str_replace("\262", "╡", $string);
391 $string = str_replace("\263", "Ё", $string);
392 $string = str_replace("\264", "╢", $string);
393 $string = str_replace("\265", "╣", $string);
394 $string = str_replace("\266", "╤", $string);
395 $string = str_replace("\267", "╥", $string);
396 $string = str_replace("\270", "╦", $string);
397 $string = str_replace("\271", "╧", $string);
398 $string = str_replace("\272", "╨", $string);
399 $string = str_replace("\273", "╩", $string);
400 $string = str_replace("\274", "╪", $string);
401 $string = str_replace("\275", "╫", $string);
402 $string = str_replace("\276", "╬", $string);
403 $string = str_replace("\277", "©", $string);
404 $string = str_replace("\300", "ю", $string);
405 $string = str_replace("\301", "а", $string);
406 $string = str_replace("\302", "б", $string);
407 $string = str_replace("\303", "ц", $string);
408 $string = str_replace("\304", "д", $string);
409 $string = str_replace("\305", "е", $string);
410 $string = str_replace("\306", "ф", $string);
411 $string = str_replace("\307", "г", $string);
412 $string = str_replace("\310", "х", $string);
413 $string = str_replace("\311", "и", $string);
414 $string = str_replace("\312", "й", $string);
415 $string = str_replace("\313", "к", $string);
416 $string = str_replace("\314", "л", $string);
417 $string = str_replace("\315", "м", $string);
418 $string = str_replace("\316", "н", $string);
419 $string = str_replace("\317", "о", $string);
420 $string = str_replace("\320", "п", $string);
421 $string = str_replace("\321", "я", $string);
422 $string = str_replace("\322", "р", $string);
423 $string = str_replace("\323", "с", $string);
424 $string = str_replace("\324", "т", $string);
425 $string = str_replace("\325", "у", $string);
426 $string = str_replace("\326", "ж", $string);
427 $string = str_replace("\327", "в", $string);
428 $string = str_replace("\330", "ь", $string);
429 $string = str_replace("\331", "ы", $string);
430 $string = str_replace("\332", "з", $string);
431 $string = str_replace("\333", "ш", $string);
432 $string = str_replace("\334", "э", $string);
433 $string = str_replace("\335", "щ", $string);
434 $string = str_replace("\336", "ч", $string);
435 $string = str_replace("\337", "ъ", $string);
436 $string = str_replace("\340", "Ю", $string);
437 $string = str_replace("\341", "А", $string);
438 $string = str_replace("\342", "Б", $string);
439 $string = str_replace("\343", "Ц", $string);
440 $string = str_replace("\344", "Д", $string);
441 $string = str_replace("\345", "Е", $string);
442 $string = str_replace("\346", "Ф", $string);
443 $string = str_replace("\347", "Г", $string);
444 $string = str_replace("\350", "Х", $string);
445 $string = str_replace("\351", "И", $string);
446 $string = str_replace("\352", "Й", $string);
447 $string = str_replace("\353", "К", $string);
448 $string = str_replace("\354", "Л", $string);
449 $string = str_replace("\355", "М", $string);
450 $string = str_replace("\356", "Н", $string);
451 $string = str_replace("\357", "О", $string);
452 $string = str_replace("\360", "П", $string);
453 $string = str_replace("\361", "Я", $string);
454 $string = str_replace("\362", "Р", $string);
455 $string = str_replace("\363", "С", $string);
456 $string = str_replace("\364", "Т", $string);
457 $string = str_replace("\365", "У", $string);
458 $string = str_replace("\366", "Ж", $string);
459 $string = str_replace("\367", "В", $string);
460 $string = str_replace("\370", "Ь", $string);
461 $string = str_replace("\371", "Ы", $string);
462 $string = str_replace("\372", "З", $string);
463 $string = str_replace("\373", "Ш", $string);
464 $string = str_replace("\374", "Э", $string);
465 $string = str_replace("\375", "Щ", $string);
466 $string = str_replace("\376", "Ч", $string);
467 $string = str_replace("\377", "Ъ", $string);