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