Dave Huang <khym+skwirl@azeotrope.org> html format reporting
[squirrelmail.git] / functions / i18n.php
CommitLineData
59177427 1<?php
1fd97780 2
35586184 3/**
4 * i18n.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
11 *
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
14 *
15 * $Id$
16 */
17
a2a7852b 18/* Decodes a string to the internal encoding from the given charset */
19function charset_decode ($charset, $string) {
20 global $debug_mime;
21
22 /* All HTML special characters are 7 bit and can be replaced first */
23 $string = htmlspecialchars ($string);
24
25 $charset = strtolower($charset);
26
27 if ($debug_mime) $string = $charset . ':' . $string;
28
29 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
30 if ($res[1] == '1') {
31 $ret = charset_decode_iso_8859_1 ($string);
32 } else if ($res[1] == '2') {
33 $ret = charset_decode_iso_8859_2 ($string);
34 } else if ($res[1] == '7') {
35 $ret = charset_decode_iso_8859_7 ($string);
36 } else if ($res[1] == '15') {
37 $ret = charset_decode_iso_8859_15 ($string);
38 } else {
39 $ret = charset_decode_iso_8859_default ($string);
40 }
41 } else if ($charset == 'ns_4551-1') {
42 $ret = charset_decode_ns_4551_1 ($string);
43 } else if ($charset == 'koi8-r') {
44 $ret = charset_decode_koi8r ($string);
45 } else if ($charset == 'windows-1251') {
46 $ret = charset_decode_koi8r ($string);
47 } else {
48 $ret = $string;
49 }
50 return( $ret );
51}
52
53/*
54 iso-8859-1 is the same as Latin 1 and is normally used
55 in western europe.
56 */
57function charset_decode_iso_8859_1 ($string) {
58 global $default_charset;
13e0c649 59
a2a7852b 60 if (strtolower($default_charset) <> 'iso-8859-1') {
61 /* Only do the slow convert if there are 8-bit characters */
62 if (ereg("[\200-\377]", $string)) {
066c374f 63 $string = str_replace("\201", '&#129;', $string);
64 $string = str_replace("\202", '&#130;', $string);
65 $string = str_replace("\203", '&#131;', $string);
66 $string = str_replace("\204", '&#132;', $string);
67 $string = str_replace("\205", '&#133;', $string);
68 $string = str_replace("\206", '&#134;', $string);
69 $string = str_replace("\207", '&#135;', $string);
70 $string = str_replace("\210", '&#136;', $string);
71 $string = str_replace("\211", '&#137;', $string);
72 $string = str_replace("\212", '&#138;', $string);
73 $string = str_replace("\213", '&#139;', $string);
74 $string = str_replace("\214", '&#140;', $string);
75 $string = str_replace("\215", '&#141;', $string);
76 $string = str_replace("\216", '&#142;', $string);
77 $string = str_replace("\217", '&#143;', $string);
78 $string = str_replace("\220", '&#144;', $string);
79 $string = str_replace("\221", '&#145;', $string);
80 $string = str_replace("\222", '&#146;', $string);
81 $string = str_replace("\223", '&#147;', $string);
82 $string = str_replace("\224", '&#148;', $string);
83 $string = str_replace("\225", '&#149;', $string);
84 $string = str_replace("\226", '&#150;', $string);
85 $string = str_replace("\227", '&#151;', $string);
86 $string = str_replace("\230", '&#152;', $string);
87 $string = str_replace("\231", '&#153;', $string);
88 $string = str_replace("\232", '&#154;', $string);
89 $string = str_replace("\233", '&#155;', $string);
90 $string = str_replace("\234", '&#156;', $string);
91 $string = str_replace("\235", '&#157;', $string);
92 $string = str_replace("\236", '&#158;', $string);
93 $string = str_replace("\237", '&#159;', $string);
94 $string = str_replace("\240", '&#160;', $string);
95 $string = str_replace("\241", '&#161;', $string);
96 $string = str_replace("\242", '&#162;', $string);
97 $string = str_replace("\243", '&#163;', $string);
98 $string = str_replace("\244", '&#164;', $string);
99 $string = str_replace("\245", '&#165;', $string);
100 $string = str_replace("\246", '&#166;', $string);
101 $string = str_replace("\247", '&#167;', $string);
102 $string = str_replace("\250", '&#168;', $string);
103 $string = str_replace("\251", '&#169;', $string);
104 $string = str_replace("\252", '&#170;', $string);
105 $string = str_replace("\253", '&#171;', $string);
106 $string = str_replace("\254", '&#172;', $string);
107 $string = str_replace("\255", '&#173;', $string);
108 $string = str_replace("\256", '&#174;', $string);
109 $string = str_replace("\257", '&#175;', $string);
110 $string = str_replace("\260", '&#176;', $string);
111 $string = str_replace("\261", '&#177;', $string);
112 $string = str_replace("\262", '&#178;', $string);
113 $string = str_replace("\263", '&#179;', $string);
114 $string = str_replace("\264", '&#180;', $string);
115 $string = str_replace("\265", '&#181;', $string);
116 $string = str_replace("\266", '&#182;', $string);
117 $string = str_replace("\267", '&#183;', $string);
118 $string = str_replace("\270", '&#184;', $string);
119 $string = str_replace("\271", '&#185;', $string);
120 $string = str_replace("\272", '&#186;', $string);
121 $string = str_replace("\273", '&#187;', $string);
122 $string = str_replace("\274", '&#188;', $string);
123 $string = str_replace("\275", '&#189;', $string);
124 $string = str_replace("\276", '&#190;', $string);
125 $string = str_replace("\277", '&#191;', $string);
126 $string = str_replace("\300", '&#192;', $string);
127 $string = str_replace("\301", '&#193;', $string);
128 $string = str_replace("\302", '&#194;', $string);
129 $string = str_replace("\303", '&#195;', $string);
130 $string = str_replace("\304", '&#196;', $string);
131 $string = str_replace("\305", '&#197;', $string);
132 $string = str_replace("\306", '&#198;', $string);
133 $string = str_replace("\307", '&#199;', $string);
134 $string = str_replace("\310", '&#200;', $string);
135 $string = str_replace("\311", '&#201;', $string);
136 $string = str_replace("\312", '&#202;', $string);
137 $string = str_replace("\313", '&#203;', $string);
138 $string = str_replace("\314", '&#204;', $string);
139 $string = str_replace("\315", '&#205;', $string);
140 $string = str_replace("\316", '&#206;', $string);
141 $string = str_replace("\317", '&#207;', $string);
142 $string = str_replace("\320", '&#208;', $string);
143 $string = str_replace("\321", '&#209;', $string);
144 $string = str_replace("\322", '&#210;', $string);
145 $string = str_replace("\323", '&#211;', $string);
146 $string = str_replace("\324", '&#212;', $string);
147 $string = str_replace("\325", '&#213;', $string);
148 $string = str_replace("\326", '&#214;', $string);
149 $string = str_replace("\327", '&#215;', $string);
150 $string = str_replace("\330", '&#216;', $string);
151 $string = str_replace("\331", '&#217;', $string);
152 $string = str_replace("\332", '&#218;', $string);
153 $string = str_replace("\333", '&#219;', $string);
154 $string = str_replace("\334", '&#220;', $string);
155 $string = str_replace("\335", '&#221;', $string);
156 $string = str_replace("\336", '&#222;', $string);
157 $string = str_replace("\337", '&#223;', $string);
158 $string = str_replace("\340", '&#224;', $string);
159 $string = str_replace("\341", '&#225;', $string);
160 $string = str_replace("\342", '&#226;', $string);
161 $string = str_replace("\343", '&#227;', $string);
162 $string = str_replace("\344", '&#228;', $string);
163 $string = str_replace("\345", '&#229;', $string);
164 $string = str_replace("\346", '&#230;', $string);
165 $string = str_replace("\347", '&#231;', $string);
166 $string = str_replace("\350", '&#232;', $string);
167 $string = str_replace("\351", '&#233;', $string);
168 $string = str_replace("\352", '&#234;', $string);
169 $string = str_replace("\353", '&#235;', $string);
170 $string = str_replace("\354", '&#236;', $string);
171 $string = str_replace("\355", '&#237;', $string);
172 $string = str_replace("\356", '&#238;', $string);
173 $string = str_replace("\357", '&#239;', $string);
174 $string = str_replace("\360", '&#240;', $string);
175 $string = str_replace("\361", '&#241;', $string);
176 $string = str_replace("\362", '&#242;', $string);
177 $string = str_replace("\363", '&#243;', $string);
178 $string = str_replace("\364", '&#244;', $string);
179 $string = str_replace("\365", '&#245;', $string);
180 $string = str_replace("\366", '&#246;', $string);
181 $string = str_replace("\367", '&#247;', $string);
182 $string = str_replace("\370", '&#248;', $string);
183 $string = str_replace("\371", '&#249;', $string);
184 $string = str_replace("\372", '&#250;', $string);
185 $string = str_replace("\373", '&#251;', $string);
186 $string = str_replace("\374", '&#252;', $string);
187 $string = str_replace("\375", '&#253;', $string);
188 $string = str_replace("\376", '&#254;', $string);
189 $string = str_replace("\377", '&#255;', $string);
a2a7852b 190 }
191 }
192
193 return ($string);
194}
195
196/* iso-8859-2 is used for some eastern European languages */
197function charset_decode_iso_8859_2 ($string) {
198 global $default_charset;
199
200 if (strtolower($default_charset) == 'iso-8859-2')
201 return $string;
202
203 /* Only do the slow convert if there are 8-bit characters */
204 if (! ereg("[\200-\377]", $string))
205 return $string;
206
207 /* NO-BREAK SPACE */
208 $string = str_replace("\240", '&#160;', $string);
209 /* LATIN CAPITAL LETTER A WITH OGONEK */
210 $string = str_replace("\241", '&#260;', $string);
211 /* BREVE */
212 $string = str_replace("\242", '&#728;', $string);
213 // LATIN CAPITAL LETTER L WITH STROKE
214 $string = str_replace("\243", '&#321;', $string);
215 // CURRENCY SIGN
216 $string = str_replace("\244", '&#164;', $string);
217 // LATIN CAPITAL LETTER L WITH CARON
218 $string = str_replace("\245", '&#317;', $string);
219 // LATIN CAPITAL LETTER S WITH ACUTE
220 $string = str_replace("\246", '&#346;', $string);
221 // SECTION SIGN
222 $string = str_replace("\247", '&#167;', $string);
223 // DIAERESIS
224 $string = str_replace("\250", '&#168;', $string);
225 // LATIN CAPITAL LETTER S WITH CARON
226 $string = str_replace("\251", '&#352;', $string);
227 // LATIN CAPITAL LETTER S WITH CEDILLA
228 $string = str_replace("\252", '&#350;', $string);
229 // LATIN CAPITAL LETTER T WITH CARON
230 $string = str_replace("\253", '&#356;', $string);
231 // LATIN CAPITAL LETTER Z WITH ACUTE
232 $string = str_replace("\254", '&#377;', $string);
233 // SOFT HYPHEN
234 $string = str_replace("\255", '&#173;', $string);
235 // LATIN CAPITAL LETTER Z WITH CARON
236 $string = str_replace("\256", '&#381;', $string);
237 // LATIN CAPITAL LETTER Z WITH DOT ABOVE
238 $string = str_replace("\257", '&#379;', $string);
239 // DEGREE SIGN
240 $string = str_replace("\260", '&#176;', $string);
241 // LATIN SMALL LETTER A WITH OGONEK
242 $string = str_replace("\261", '&#261;', $string);
243 // OGONEK
244 $string = str_replace("\262", '&#731;', $string);
245 // LATIN SMALL LETTER L WITH STROKE
246 $string = str_replace("\263", '&#322;', $string);
247 // ACUTE ACCENT
248 $string = str_replace("\264", '&#180;', $string);
249 // LATIN SMALL LETTER L WITH CARON
250 $string = str_replace("\265", '&#318;', $string);
251 // LATIN SMALL LETTER S WITH ACUTE
252 $string = str_replace("\266", '&#347;', $string);
253 // CARON
254 $string = str_replace("\267", '&#711;', $string);
255 // CEDILLA
256 $string = str_replace("\270", '&#184;', $string);
257 // LATIN SMALL LETTER S WITH CARON
258 $string = str_replace("\271", '&#353;', $string);
259 // LATIN SMALL LETTER S WITH CEDILLA
260 $string = str_replace("\272", '&#351;', $string);
261 // LATIN SMALL LETTER T WITH CARON
262 $string = str_replace("\273", '&#357;', $string);
263 // LATIN SMALL LETTER Z WITH ACUTE
264 $string = str_replace("\274", '&#378;', $string);
265 // DOUBLE ACUTE ACCENT
266 $string = str_replace("\275", '&#733;', $string);
267 // LATIN SMALL LETTER Z WITH CARON
268 $string = str_replace("\276", '&#382;', $string);
269 // LATIN SMALL LETTER Z WITH DOT ABOVE
270 $string = str_replace("\277", '&#380;', $string);
271 // LATIN CAPITAL LETTER R WITH ACUTE
272 $string = str_replace("\300", '&#340;', $string);
273 // LATIN CAPITAL LETTER A WITH ACUTE
274 $string = str_replace("\301", '&#193;', $string);
275 // LATIN CAPITAL LETTER A WITH CIRCUMFLEX
276 $string = str_replace("\302", '&#194;', $string);
277 // LATIN CAPITAL LETTER A WITH BREVE
278 $string = str_replace("\303", '&#258;', $string);
279 // LATIN CAPITAL LETTER A WITH DIAERESIS
280 $string = str_replace("\304", '&#196;', $string);
281 // LATIN CAPITAL LETTER L WITH ACUTE
282 $string = str_replace("\305", '&#313;', $string);
283 // LATIN CAPITAL LETTER C WITH ACUTE
284 $string = str_replace("\306", '&#262;', $string);
285 // LATIN CAPITAL LETTER C WITH CEDILLA
286 $string = str_replace("\307", '&#199;', $string);
287 // LATIN CAPITAL LETTER C WITH CARON
288 $string = str_replace("\310", '&#268;', $string);
289 // LATIN CAPITAL LETTER E WITH ACUTE
290 $string = str_replace("\311", '&#201;', $string);
291 // LATIN CAPITAL LETTER E WITH OGONEK
292 $string = str_replace("\312", '&#280;', $string);
293 // LATIN CAPITAL LETTER E WITH DIAERESIS
294 $string = str_replace("\313", '&#203;', $string);
295 // LATIN CAPITAL LETTER E WITH CARON
296 $string = str_replace("\314", '&#282;', $string);
297 // LATIN CAPITAL LETTER I WITH ACUTE
298 $string = str_replace("\315", '&#205;', $string);
299 // LATIN CAPITAL LETTER I WITH CIRCUMFLEX
300 $string = str_replace("\316", '&#206;', $string);
301 // LATIN CAPITAL LETTER D WITH CARON
302 $string = str_replace("\317", '&#270;', $string);
303 // LATIN CAPITAL LETTER D WITH STROKE
304 $string = str_replace("\320", '&#272;', $string);
305 // LATIN CAPITAL LETTER N WITH ACUTE
306 $string = str_replace("\321", '&#323;', $string);
307 // LATIN CAPITAL LETTER N WITH CARON
308 $string = str_replace("\322", '&#327;', $string);
309 // LATIN CAPITAL LETTER O WITH ACUTE
310 $string = str_replace("\323", '&#211;', $string);
311 // LATIN CAPITAL LETTER O WITH CIRCUMFLEX
312 $string = str_replace("\324", '&#212;', $string);
313 // LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
314 $string = str_replace("\325", '&#336;', $string);
315 // LATIN CAPITAL LETTER O WITH DIAERESIS
316 $string = str_replace("\326", '&#214;', $string);
317 // MULTIPLICATION SIGN
318 $string = str_replace("\327", '&#215;', $string);
319 // LATIN CAPITAL LETTER R WITH CARON
320 $string = str_replace("\330", '&#344;', $string);
321 // LATIN CAPITAL LETTER U WITH RING ABOVE
322 $string = str_replace("\331", '&#366;', $string);
323 // LATIN CAPITAL LETTER U WITH ACUTE
324 $string = str_replace("\332", '&#218;', $string);
325 // LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
326 $string = str_replace("\333", '&#368;', $string);
327 // LATIN CAPITAL LETTER U WITH DIAERESIS
328 $string = str_replace("\334", '&#220;', $string);
329 // LATIN CAPITAL LETTER Y WITH ACUTE
330 $string = str_replace("\335", '&#221;', $string);
331 // LATIN CAPITAL LETTER T WITH CEDILLA
332 $string = str_replace("\336", '&#354;', $string);
333 // LATIN SMALL LETTER SHARP S
334 $string = str_replace("\337", '&#223;', $string);
335 // LATIN SMALL LETTER R WITH ACUTE
336 $string = str_replace("\340", '&#341;', $string);
337 // LATIN SMALL LETTER A WITH ACUTE
338 $string = str_replace("\341", '&#225;', $string);
339 // LATIN SMALL LETTER A WITH CIRCUMFLEX
340 $string = str_replace("\342", '&#226;', $string);
341 // LATIN SMALL LETTER A WITH BREVE
342 $string = str_replace("\343", '&#259;', $string);
343 // LATIN SMALL LETTER A WITH DIAERESIS
344 $string = str_replace("\344", '&#228;', $string);
345 // LATIN SMALL LETTER L WITH ACUTE
346 $string = str_replace("\345", '&#314;', $string);
347 // LATIN SMALL LETTER C WITH ACUTE
348 $string = str_replace("\346", '&#263;', $string);
349 // LATIN SMALL LETTER C WITH CEDILLA
350 $string = str_replace("\347", '&#231;', $string);
351 // LATIN SMALL LETTER C WITH CARON
352 $string = str_replace("\350", '&#269;', $string);
353 // LATIN SMALL LETTER E WITH ACUTE
354 $string = str_replace("\351", '&#233;', $string);
355 // LATIN SMALL LETTER E WITH OGONEK
356 $string = str_replace("\352", '&#281;', $string);
357 // LATIN SMALL LETTER E WITH DIAERESIS
358 $string = str_replace("\353", '&#235;', $string);
359 // LATIN SMALL LETTER E WITH CARON
360 $string = str_replace("\354", '&#283;', $string);
361 // LATIN SMALL LETTER I WITH ACUTE
362 $string = str_replace("\355", '&#237;', $string);
363 // LATIN SMALL LETTER I WITH CIRCUMFLEX
364 $string = str_replace("\356", '&#238;', $string);
365 // LATIN SMALL LETTER D WITH CARON
366 $string = str_replace("\357", '&#271;', $string);
367 // LATIN SMALL LETTER D WITH STROKE
368 $string = str_replace("\360", '&#273;', $string);
369 // LATIN SMALL LETTER N WITH ACUTE
370 $string = str_replace("\361", '&#324;', $string);
371 // LATIN SMALL LETTER N WITH CARON
372 $string = str_replace("\362", '&#328;', $string);
373 // LATIN SMALL LETTER O WITH ACUTE
374 $string = str_replace("\363", '&#243;', $string);
375 // LATIN SMALL LETTER O WITH CIRCUMFLEX
376 $string = str_replace("\364", '&#244;', $string);
377 // LATIN SMALL LETTER O WITH DOUBLE ACUTE
378 $string = str_replace("\365", '&#337;', $string);
379 // LATIN SMALL LETTER O WITH DIAERESIS
380 $string = str_replace("\366", '&#246;', $string);
381 // DIVISION SIGN
382 $string = str_replace("\367", '&#247;', $string);
383 // LATIN SMALL LETTER R WITH CARON
384 $string = str_replace("\370", '&#345;', $string);
385 // LATIN SMALL LETTER U WITH RING ABOVE
386 $string = str_replace("\371", '&#367;', $string);
387 // LATIN SMALL LETTER U WITH ACUTE
388 $string = str_replace("\372", '&#250;', $string);
389 // LATIN SMALL LETTER U WITH DOUBLE ACUTE
390 $string = str_replace("\373", '&#369;', $string);
391 // LATIN SMALL LETTER U WITH DIAERESIS
392 $string = str_replace("\374", '&#252;', $string);
393 // LATIN SMALL LETTER Y WITH ACUTE
394 $string = str_replace("\375", '&#253;', $string);
395 // LATIN SMALL LETTER T WITH CEDILLA
396 $string = str_replace("\376", '&#355;', $string);
397 // DOT ABOVE
398 $string = str_replace("\377", '&#729;', $string);
399
400 return $string;
401}
402
403/* iso-8859-7 is Greek. */
404function charset_decode_iso_8859_7 ($string) {
405 global $default_charset;
406
407 if (strtolower($default_charset) == 'iso-8859-7') {
408 return $string;
409 }
410
411 /* Only do the slow convert if there are 8-bit characters */
412 if (!ereg("[\200-\377]", $string)) {
413 return $string;
414 }
415
416 /* Some diverse characters in the beginning */
417 $string = str_replace("\240", '&#160;', $string);
418 $string = str_replace("\241", '&#8216;', $string);
419 $string = str_replace("\242", '&#8217;', $string);
420 $string = str_replace("\243", '&#163;', $string);
421 $string = str_replace("\246", '&#166;', $string);
422 $string = str_replace("\247", '&#167;', $string);
423 $string = str_replace("\250", '&#168;', $string);
424 $string = str_replace("\251", '&#169;', $string);
425 $string = str_replace("\253", '&#171;', $string);
426 $string = str_replace("\254", '&#172;', $string);
427 $string = str_replace("\255", '&#173;', $string);
428 $string = str_replace("\257", '&#8213;', $string);
429 $string = str_replace("\260", '&#176;', $string);
430 $string = str_replace("\261", '&#177;', $string);
431 $string = str_replace("\262", '&#178;', $string);
432 $string = str_replace("\263", '&#179;', $string);
433
434 /* Horizontal bar (parentheki pavla) */
435 $string = str_replace ("\257", '&#8213;', $string);
436
437 /*
438 * ISO-8859-7 characters from 11/04 (0xB4) to 11/06 (0xB6)
439 * These are Unicode 900-902
440 */
441 while (ereg("([\264-\266])", $string, $res)) {
442 $replace = '&#' . (ord($res[1])+720) . ';';
443 $string = str_replace($res[1], $replace, $string);
444 }
445
446 /* 11/07 (0xB7) Middle dot is the same in iso-8859-1 */
447 $string = str_replace("\267", '&#183;', $string);
448
449 /*
450 * ISO-8859-7 characters from 11/08 (0xB8) to 11/10 (0xBA)
451 * These are Unicode 900-902
452 */
453 while (ereg("([\270-\272])", $string, $res)) {
454 $replace = '&#' . (ord($res[1])+720) . ";";
455 $string = str_replace($res[1], $replace, $string);
456 }
457
458 /*
459 * 11/11 (0xBB) Right angle quotation mark is the same as in
460 * iso-8859-1
461 */
462 $string = str_replace("\273", '&#187;', $string);
463
464 /* And now the rest of the charset */
465 while (ereg("([\274-\376])", $string, $res)) {
466 $replace = '&#' . (ord($res[1])+720) . ';';
467 $string = str_replace($res[1], $replace, $string);
468 }
469
470 return $string;
471}
472
473/*
474 * iso-8859-15 is Latin 9 and has very much the same use as Latin 1
475 * but has the Euro symbol and some characters needed for French.
476 */
477function charset_decode_iso_8859_15 ($string) {
478 // Euro sign
479 $string = str_replace ("\244", '&#8364;', $string);
480 // Latin capital letter S with caron
481 $string = str_replace ("\244", '&#352;', $string);
482 // Latin small letter s with caron
483 $string = str_replace ("\250", '&#353;', $string);
484 // Latin capital letter Z with caron
485 $string = str_replace ("\264", '&#381;', $string);
486 // Latin small letter z with caron
487 $string = str_replace ("\270", '&#382;', $string);
488 // Latin capital ligature OE
489 $string = str_replace ("\274", '&#338;', $string);
490 // Latin small ligature oe
491 $string = str_replace ("\275", '&#339;', $string);
492 // Latin capital letter Y with diaeresis
493 $string = str_replace ("\276", '&#376;', $string);
494
495 return (charset_decode_iso_8859_1($string));
496}
497
498/* ISO-8859-15 is Cyrillic */
499function charset_decode_iso_8859_5 ($string) {
500 // Convert to KOI8-R, then return this decoded.
501 $string = convert_cyr_string($string, 'i', 'k');
502 return charset_decode_koi8r($string);
503}
504
505/* Remove all 8 bit characters from all other ISO-8859 character sets */
506function charset_decode_iso_8859_default ($string) {
507 return (strtr($string, "\240\241\242\243\244\245\246\247".
1fd97780 508 "\250\251\252\253\254\255\256\257".
509 "\260\261\262\263\264\265\266\267".
510 "\270\271\272\273\274\275\276\277".
511 "\300\301\302\303\304\305\306\307".
512 "\310\311\312\313\314\315\316\317".
513 "\320\321\322\323\324\325\326\327".
514 "\330\331\332\333\334\335\336\337".
515 "\340\341\342\343\344\345\346\347".
516 "\350\351\352\353\354\355\356\357".
517 "\360\361\362\363\364\365\366\367".
a2a7852b 518 "\370\371\372\373\374\375\376\377",
1fd97780 519 "????????????????????????????????????????".
520 "????????????????????????????????????????".
521 "????????????????????????????????????????".
522 "????????"));
a2a7852b 523
524}
525
526/*
527 * This is the same as ISO-646-NO and is used by some
528 * Microsoft programs when sending Norwegian characters
529 */
530function charset_decode_ns_4551_1 ($string) {
531 /*
532 * These characters are:
533 * Latin capital letter AE
534 * Latin capital letter O with stroke
535 * Latin capital letter A with ring above
536 * and the same as small letters
537 */
538 return strtr ($string, "[\\]{|}", "");
539}
540
541/*
542 * KOI8-R is used to encode Russian mail (Cyrrilic). Defined in RFC
543 * 1489.
544 */
545function charset_decode_koi8r ($string) {
546 global $default_charset;
547
548 if ($default_charset == 'koi8-r') {
549 return $string;
550 }
551
552 /*
553 * Convert to Unicode HTML entities.
554 * This code is rather ineffective.
555 */
556 $string = str_replace("\200", '&#9472;', $string);
557 $string = str_replace("\201", '&#9474;', $string);
558 $string = str_replace("\202", '&#9484;', $string);
559 $string = str_replace("\203", '&#9488;', $string);
560 $string = str_replace("\204", '&#9492;', $string);
561 $string = str_replace("\205", '&#9496;', $string);
562 $string = str_replace("\206", '&#9500;', $string);
563 $string = str_replace("\207", '&#9508;', $string);
564 $string = str_replace("\210", '&#9516;', $string);
565 $string = str_replace("\211", '&#9524;', $string);
566 $string = str_replace("\212", '&#9532;', $string);
567 $string = str_replace("\213", '&#9600;', $string);
568 $string = str_replace("\214", '&#9604;', $string);
569 $string = str_replace("\215", '&#9608;', $string);
570 $string = str_replace("\216", '&#9612;', $string);
571 $string = str_replace("\217", '&#9616;', $string);
572 $string = str_replace("\220", '&#9617;', $string);
573 $string = str_replace("\221", '&#9618;', $string);
574 $string = str_replace("\222", '&#9619;', $string);
575 $string = str_replace("\223", '&#8992;', $string);
576 $string = str_replace("\224", '&#9632;', $string);
577 $string = str_replace("\225", '&#8729;', $string);
578 $string = str_replace("\226", '&#8730;', $string);
579 $string = str_replace("\227", '&#8776;', $string);
580 $string = str_replace("\230", '&#8804;', $string);
581 $string = str_replace("\231", '&#8805;', $string);
582 $string = str_replace("\232", '&#160;', $string);
583 $string = str_replace("\233", '&#8993;', $string);
584 $string = str_replace("\234", '&#176;', $string);
585 $string = str_replace("\235", '&#178;', $string);
586 $string = str_replace("\236", '&#183;', $string);
587 $string = str_replace("\237", '&#247;', $string);
588 $string = str_replace("\240", '&#9552;', $string);
589 $string = str_replace("\241", '&#9553;', $string);
590 $string = str_replace("\242", '&#9554;', $string);
591 $string = str_replace("\243", '&#1105;', $string);
592 $string = str_replace("\244", '&#9555;', $string);
593 $string = str_replace("\245", '&#9556;', $string);
594 $string = str_replace("\246", '&#9557;', $string);
595 $string = str_replace("\247", '&#9558;', $string);
596 $string = str_replace("\250", '&#9559;', $string);
597 $string = str_replace("\251", '&#9560;', $string);
598 $string = str_replace("\252", '&#9561;', $string);
599 $string = str_replace("\253", '&#9562;', $string);
600 $string = str_replace("\254", '&#9563;', $string);
601 $string = str_replace("\255", '&#9564;', $string);
602 $string = str_replace("\256", '&#9565;', $string);
603 $string = str_replace("\257", '&#9566;', $string);
604 $string = str_replace("\260", '&#9567;', $string);
605 $string = str_replace("\261", '&#9568;', $string);
606 $string = str_replace("\262", '&#9569;', $string);
607 $string = str_replace("\263", '&#1025;', $string);
608 $string = str_replace("\264", '&#9570;', $string);
609 $string = str_replace("\265", '&#9571;', $string);
610 $string = str_replace("\266", '&#9572;', $string);
611 $string = str_replace("\267", '&#9573;', $string);
612 $string = str_replace("\270", '&#9574;', $string);
613 $string = str_replace("\271", '&#9575;', $string);
614 $string = str_replace("\272", '&#9576;', $string);
615 $string = str_replace("\273", '&#9577;', $string);
616 $string = str_replace("\274", '&#9578;', $string);
617 $string = str_replace("\275", '&#9579;', $string);
618 $string = str_replace("\276", '&#9580;', $string);
619 $string = str_replace("\277", '&#169;', $string);
620 $string = str_replace("\300", '&#1102;', $string);
621 $string = str_replace("\301", '&#1072;', $string);
622 $string = str_replace("\302", '&#1073;', $string);
623 $string = str_replace("\303", '&#1094;', $string);
624 $string = str_replace("\304", '&#1076;', $string);
625 $string = str_replace("\305", '&#1077;', $string);
626 $string = str_replace("\306", '&#1092;', $string);
627 $string = str_replace("\307", '&#1075;', $string);
628 $string = str_replace("\310", '&#1093;', $string);
629 $string = str_replace("\311", '&#1080;', $string);
630 $string = str_replace("\312", '&#1081;', $string);
631 $string = str_replace("\313", '&#1082;', $string);
632 $string = str_replace("\314", '&#1083;', $string);
633 $string = str_replace("\315", '&#1084;', $string);
634 $string = str_replace("\316", '&#1085;', $string);
635 $string = str_replace("\317", '&#1086;', $string);
636 $string = str_replace("\320", '&#1087;', $string);
637 $string = str_replace("\321", '&#1103;', $string);
638 $string = str_replace("\322", '&#1088;', $string);
639 $string = str_replace("\323", '&#1089;', $string);
640 $string = str_replace("\324", '&#1090;', $string);
641 $string = str_replace("\325", '&#1091;', $string);
642 $string = str_replace("\326", '&#1078;', $string);
643 $string = str_replace("\327", '&#1074;', $string);
644 $string = str_replace("\330", '&#1100;', $string);
645 $string = str_replace("\331", '&#1099;', $string);
646 $string = str_replace("\332", '&#1079;', $string);
647 $string = str_replace("\333", '&#1096;', $string);
648 $string = str_replace("\334", '&#1101;', $string);
649 $string = str_replace("\335", '&#1097;', $string);
650 $string = str_replace("\336", '&#1095;', $string);
651 $string = str_replace("\337", '&#1098;', $string);
652 $string = str_replace("\340", '&#1070;', $string);
653 $string = str_replace("\341", '&#1040;', $string);
654 $string = str_replace("\342", '&#1041;', $string);
655 $string = str_replace("\343", '&#1062;', $string);
656 $string = str_replace("\344", '&#1044;', $string);
657 $string = str_replace("\345", '&#1045;', $string);
658 $string = str_replace("\346", '&#1060;', $string);
659 $string = str_replace("\347", '&#1043;', $string);
660 $string = str_replace("\350", '&#1061;', $string);
661 $string = str_replace("\351", '&#1048;', $string);
662 $string = str_replace("\352", '&#1049;', $string);
663 $string = str_replace("\353", '&#1050;', $string);
664 $string = str_replace("\354", '&#1051;', $string);
665 $string = str_replace("\355", '&#1052;', $string);
666 $string = str_replace("\356", '&#1053;', $string);
667 $string = str_replace("\357", '&#1054;', $string);
668 $string = str_replace("\360", '&#1055;', $string);
669 $string = str_replace("\361", '&#1071;', $string);
670 $string = str_replace("\362", '&#1056;', $string);
671 $string = str_replace("\363", '&#1057;', $string);
672 $string = str_replace("\364", '&#1058;', $string);
673 $string = str_replace("\365", '&#1059;', $string);
674 $string = str_replace("\366", '&#1046;', $string);
675 $string = str_replace("\367", '&#1042;', $string);
676 $string = str_replace("\370", '&#1068;', $string);
677 $string = str_replace("\371", '&#1067;', $string);
678 $string = str_replace("\372", '&#1047;', $string);
679 $string = str_replace("\373", '&#1064;', $string);
680 $string = str_replace("\374", '&#1069;', $string);
681 $string = str_replace("\375", '&#1065;', $string);
682 $string = str_replace("\376", '&#1063;', $string);
683 $string = str_replace("\377", '&#1066;', $string);
684
685 return $string;
686}
687
688/*
689 * Set up the language to be output
690 * if $do_search is true, then scan the browser information
691 * for a possible language that we know
692 */
693function set_up_language($sm_language, $do_search = false) {
694
695 static $SetupAlready = 0;
696 global $HTTP_ACCEPT_LANGUAGE, $use_gettext, $languages,
697 $squirrelmail_language, $squirrelmail_default_language,
698 $sm_notAlias;
699
700 if ($SetupAlready) {
701 return;
702 }
703
704 $SetupAlready = 1;
705
706 $charset_headers_sent = FALSE;
707
708 if ($do_search && ! $sm_language && isset($HTTP_ACCEPT_LANGUAGE)) {
709 $sm_language = substr($HTTP_ACCEPT_LANGUAGE, 0, 2);
710 }
711 if (!$sm_language && isset($squirrelmail_default_language)) {
712 $squirrelmail_language = $squirrelmail_default_language;
713 }
714 $sm_notAlias = $sm_language;
715 while (isset($languages[$sm_notAlias]['ALIAS'])) {
716 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
717 }
718
719 if (isset($sm_language) && $use_gettext &&
720 $sm_language != '' &&
721 isset($languages[$sm_notAlias]['CHARSET'])) {
722 if ((ini_get('safe_mode') == FALSE) && (getenv('LC_ALL') != $sm_language)) {
723 putenv('LC_ALL=' . $sm_notAlias);
724 }
725 setlocale('LC_ALL', $sm_notAlias);
726 bindtextdomain('squirrelmail', '../locale/');
727 textdomain('squirrelmail');
728 header ('Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET']);
729 }
730}
731
732function set_my_charset(){
733
734 /*
735 * There can be a $default_charset setting in the
736 * config.php file, but the user may have a different language
737 * selected for a user interface. This function checks the
738 * language selected by the user and tags the outgoing messages
739 * with the appropriate charset corresponding to the language
740 * selection. This is "more right" (tm), than just stamping the
741 * message blindly with the system-wide $default_charset.
742 */
743 global $data_dir, $username, $default_charset, $languages;
744 $my_language = getPref($data_dir, $username, 'language');
745 if (!$my_language) return;
746 while (isset($languages[$my_language]['ALIAS'])) {
f7e8861e 747 $my_language = $languages[$my_language]['ALIAS'];
a2a7852b 748 }
749 $my_charset=$languages[$my_language]['CHARSET'];
750 if ($my_charset) {
751 $default_charset = $my_charset;
752 }
753}
754
755
756/* ------------------------------ main --------------------------- */
757
758global $squirrelmail_language, $languages;
759if (! isset($squirrelmail_language)) {
760 $squirrelmail_language = '';
761}
762
763/* This array specifies the available languages. */
764$languages['ca']['NAME'] = 'Catalan';
765$languages['ca']['CHARSET'] = 'iso-8859-1';
766$languages['ca_CA']['ALIAS'] = 'ca';
767
768/* PLEASE DON'T TOUCH!!!
769 * Correct locale name, which should be set by setlocale and/or putenv('LC_ALL='...)
770 * is 'cs_CZ' and NOT 'cs', this applies to all locale names, look into docs, if you
771 * don't believe me. Ondrej Sury, czech and slovak translator.
772 */
773$languages['cs_CZ']['NAME'] = 'Czech';
774$languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
775$languages['cs']['ALIAS'] = 'cs_CZ';
776$languages['cz']['ALIAS'] = 'cs_CZ'; // set up by some ancient versions of IE
777
778$languages['da']['NAME'] = 'Danish';
779$languages['da']['CHARSET'] = 'iso-8859-1';
780$languages['da_DA']['ALIAS'] = 'da';
781
782$languages['de']['NAME'] = 'Deutsch';
783$languages['de']['CHARSET'] = 'iso-8859-1';
784$languages['de_DE']['ALIAS'] = 'de';
785
786$languages['en']['NAME'] = 'English';
787$languages['en']['CHARSET'] = 'iso-8859-1';
788$languages['en_EN']['ALIAS'] = 'en';
789
790$languages['es']['NAME'] = 'Spanish';
791$languages['es']['CHARSET'] = 'iso-8859-1';
792$languages['es_ES']['ALIAS'] = 'es';
793
794$languages['et']['NAME'] = 'Estonian';
795$languages['et']['CHARSET'] = 'iso-8859-15';
796$languages['et_EE']['ALIAS'] = 'et';
797
798$languages['fi']['NAME'] = 'Finnish';
799$languages['fi']['CHARSET'] = 'iso-8859-1';
800$languages['fi_FI']['ALIAS'] = 'fi';
801
802$languages['fr']['NAME'] = 'French';
803$languages['fr']['CHARSET'] = 'iso-8859-1';
804$languages['fr_FR']['ALIAS'] = 'fr';
805
806$languages['hr']['NAME'] = 'Croatian';
807$languages['hr']['CHARSET'] = 'iso-8859-2';
808$languages['hr_HR']['ALIAS'] = 'hr';
809
810$languages['hu']['NAME'] = 'Hungarian';
811$languages['hu']['CHARSET'] = 'iso-8859-2';
812$languages['hu_HU']['ALIAS'] = 'hu';
813
814$languages['id']['NAME'] = 'Indonesian';
815$languages['id']['CHARSET'] = 'iso-8859-1';
816$languages['id_ID']['ALIAS'] = 'id';
817
818$languages['is']['NAME'] = 'Icelandic';
819$languages['is']['CHARSET'] = 'iso-8859-1';
820$languages['is_IS']['ALIAS'] = 'is';
821
822$languages['it']['NAME'] = 'Italian';
823$languages['it']['CHARSET'] = 'iso-8859-1';
824$languages['it_IT']['ALIAS'] = 'it';
825
826$languages['ko']['NAME'] = 'Korean';
827$languages['ko']['CHARSET'] = 'euc-KR';
828$languages['ko_KO']['ALIAS'] = 'ko';
829
830$languages['nl']['NAME'] = 'Dutch';
831$languages['nl']['CHARSET'] = 'iso-8859-1';
832$languages['nl_NL']['ALIAS'] = 'nl';
833
834$languages['no']['NAME'] = 'Norwegian (Bokm&aring;l)';
835$languages['no']['CHARSET'] = 'iso-8859-1';
836$languages['no_NO']['ALIAS'] = 'no';
837$languages['no_NO_ny']['NAME'] = 'Norwegian (Nynorsk)';
838$languages['no_NO_ny']['CHARSET'] = 'iso-8859-1';
839
840$languages['pl']['NAME'] = 'Polish';
841$languages['pl']['CHARSET'] = 'iso-8859-2';
842$languages['pl_PL']['ALIAS'] = 'pl';
843
cc3326ef 844$languages['pt']['NAME'] = 'Portuguese (Portugal)';
a2a7852b 845$languages['pt']['CHARSET'] = 'iso-8859-1';
846$languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
847$languages['pt_BR']['CHARSET'] = 'iso-8859-1';
848$languages['pt_PT']['ALIAS'] = 'pt';
849
850$languages['ru']['NAME'] = 'Russian KOI8-R';
851$languages['ru']['CHARSET'] = 'koi8-r';
852$languages['ru_RU']['ALIAS'] = 'ru';
853
854$languages['sr']['NAME'] = 'Serbian';
855$languages['sr']['CHARSET'] = 'iso-8859-2';
856$languages['sr_SR']['ALIAS'] = 'sr';
857
858$languages['sv']['NAME'] = 'Swedish';
859$languages['sv']['CHARSET'] = 'iso-8859-1';
860$languages['sv_SV']['ALIAS'] = 'sv';
861
862$languages['tr']['NAME'] = 'Turkish';
863$languages['tr']['CHARSET'] = 'iso-8859-9';
864$languages['tr_TR']['ALIAS'] = 'tr';
865
866$languages['tw']['NAME'] = 'Taiwan';
867$languages['tw']['CHARSET'] = 'big5';
868$languages['tw_TW']['ALIAS'] = 'tw';
869
870$languages['sk_SK']['NAME'] = 'Slovak';
871$languages['sk_SK']['CHARSET'] = 'iso-8859-2';
872$languages['sk']['ALIAS'] = 'sk_SK';
873
874$languages['ro']['NAME'] = 'Romanian';
875$languages['ro']['CHARSET'] = 'iso-8859-2';
876$languages['ro_RO']['ALIAS'] = 'ro';
877
878$languages['th']['NAME'] = 'Thai';
879$languages['th']['CHARSET'] = 'tis-620';
880
881$languages['lt']['NAME'] = 'Lithuanian';
882$languages['lt']['CHARSET'] = 'iso-8859-13';
883$languages['lt_LT']['ALIAS'] = 'lt';
884
885$languages['sl']['NAME'] = 'Slovenian';
886$languages['sl']['CHARSET'] = 'iso-8859-2';
887
888$languages['bg']['NAME'] = 'Bulgarian';
53f5d72e 889$languages['bg']['CHARSET'] = 'windows-1251';
a2a7852b 890
891global $use_gettext;
892
893// Detect whether gettext is installed.
894$gettext_flags = 0;
895if (function_exists('_')) {
896 $gettext_flags += 1;
897}
898if (function_exists('bindtextdomain')) {
899 $gettext_flags += 2;
900}
901if (function_exists('textdomain')) {
902 $gettext_flags += 4;
903}
904
905// If gettext is fully loaded, cool
906if ($gettext_flags == 7) {
907 $use_gettext = true;
908}
909// If we can fake gettext, try that
910elseif ($gettext_flags == 0) {
911 $use_gettext = true;
912 include_once('../functions/gettext.php');
913} else {
914 // Uh-ho. A weird install
915 if (! $gettext_flags & 1) {
916 function _($str) {
917 return $str;
918 }
919 }
920 if (! $gettext_flags & 2) {
921 function bindtextdomain() {
922 return;
923 }
924 }
925 if (! $gettext_flags & 4) {
926 function textdomain() {
927 return;
928 }
929 }
930}
931
ebab5342 932
35586184 933?>