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