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