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