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