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