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