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