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