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