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