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