Add an optional link parameter to sqimap_error_box(), allow self error handling even...
[squirrelmail.git] / functions / i18n.php
1 <?php
2
3 /**
4 * i18n.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
11 *
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
14 *
15 * $Id$
16 * @package squirrelmail
17 */
18
19 /** Everything uses global.php... */
20 require_once(SM_PATH . 'functions/global.php');
21
22 /**
23 * Decodes a string to the internal encoding from the given charset
24 *
25 * @param string $charset
26 * @param string $string Text to be decoded
27 * @return string Decoded text
28 */
29 function charset_decode ($charset, $string) {
30 global $languages, $squirrelmail_language, $default_charset;
31 global $use_php_recode, $use_php_iconv, $agresive_decoding;
32
33 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
34 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
35 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
36 }
37
38 $charset = strtolower($charset);
39
40 set_my_charset();
41
42 // Variables that allow to use functions without function_exist() calls
43 if (! isset($use_php_recode) || $use_php_recode=="" ) {
44 $use_php_recode=false; }
45 if (! isset($use_php_iconv) || $use_php_iconv=="" ) {
46 $use_php_iconv=false; }
47
48 // Don't do conversion if charset is the same.
49 if ( $charset == strtolower($default_charset) )
50 return htmlspecialchars($string);
51
52 // catch iso-8859-8-i thing
53 if ( $charset == "iso-8859-8-i" )
54 $charset = "iso-8859-8";
55
56 /*
57 * Recode converts html special characters automatically if you use
58 * 'charset..html' decoding. There is no documented way to put -d option
59 * into php recode function call.
60 */
61 if ( $use_php_recode ) {
62 if ( $default_charset == "utf-8" ) {
63 // other charsets can be converted to utf-8 without loss.
64 // and output string is smaller
65 $string = recode_string($charset . "..utf-8",$string);
66 return htmlspecialchars($string);
67 } else {
68 $string = recode_string($charset . "..html",$string);
69 // recode does not convert single quote, htmlspecialchars does.
70 $string = str_replace("'", '&#039;', $string);
71 return $string;
72 }
73 }
74
75 // iconv functions does not have html target and can be used only with utf-8
76 if ( $use_php_iconv && $default_charset=='utf-8') {
77 $string = iconv($charset,$default_charset,$string);
78 return htmlspecialchars($string);
79 }
80
81 // If we don't use recode and iconv, we'll do it old way.
82
83 /* All HTML special characters are 7 bit and can be replaced first */
84
85 $string = htmlspecialchars ($string);
86
87 /* controls cpu and memory intensive decoding cycles */
88 if (! isset($agresive_decoding) || $agresive_decoding=="" ) {
89 $agresive_decoding=false; }
90
91 if (ereg('iso-8859-([[:digit:]]+)', $charset, $res)) {
92 if ($res[1] == '1') {
93 include_once(SM_PATH . 'functions/decode/iso8859-1.php');
94 $ret = charset_decode_iso8859_1 ($string);
95 } else if ($res[1] == '2') {
96 include_once(SM_PATH . 'functions/decode/iso8859-2.php');
97 $ret = charset_decode_iso8859_2 ($string);
98 } else if ($res[1] == '3') {
99 include_once(SM_PATH . 'functions/decode/iso8859-3.php');
100 $ret = charset_decode_iso8859_3 ($string);
101 } else if ($res[1] == '4') {
102 include_once(SM_PATH . 'functions/decode/iso8859-4.php');
103 $ret = charset_decode_iso8859_4 ($string);
104 } else if ($res[1] == '5') {
105 include_once(SM_PATH . 'functions/decode/iso8859-5.php');
106 $ret = charset_decode_iso8859_5 ($string);
107 } else if ($res[1] == '6') {
108 include_once(SM_PATH . 'functions/decode/iso8859-6.php');
109 $ret = charset_decode_iso8859_6 ($string);
110 } else if ($res[1] == '7') {
111 include_once(SM_PATH . 'functions/decode/iso8859-7.php');
112 $ret = charset_decode_iso8859_7 ($string);
113 } else if ($res[1] == '8') {
114 include_once(SM_PATH . 'functions/decode/iso8859-8.php');
115 $ret = charset_decode_iso8859_8 ($string);
116 } else if ($res[1] == '9') {
117 include_once(SM_PATH . 'functions/decode/iso8859-9.php');
118 $ret = charset_decode_iso8859_9 ($string);
119 } else if ($res[1] == '10') {
120 include_once(SM_PATH . 'functions/decode/iso8859-10.php');
121 $ret = charset_decode_iso8859_10 ($string);
122 } else if ($res[1] == '11') {
123 include_once(SM_PATH . 'functions/decode/iso8859-11.php');
124 $ret = charset_decode_iso8859_11 ($string);
125 } else if ($res[1] == '13') {
126 include_once(SM_PATH . 'functions/decode/iso8859-13.php');
127 $ret = charset_decode_iso8859_13 ($string);
128 } else if ($res[1] == '14') {
129 include_once(SM_PATH . 'functions/decode/iso8859-14.php');
130 $ret = charset_decode_iso8859_14 ($string);
131 } else if ($res[1] == '15') {
132 include_once(SM_PATH . 'functions/decode/iso8859-15.php');
133 $ret = charset_decode_iso8859_15 ($string);
134 } else if ($res[1] == '16') {
135 include_once(SM_PATH . 'functions/decode/iso8859-16.php');
136 $ret = charset_decode_iso8859_16 ($string);
137 } else {
138 $ret = charset_decode_iso_8859_default ($string);
139 }
140 } else if ($charset == 'ns_4551-1') {
141 $ret = charset_decode_ns_4551_1 ($string);
142 } else if ($charset == 'koi8-r') {
143 include_once(SM_PATH . 'functions/decode/koi8-r.php');
144 $ret = charset_decode_koi8r ($string);
145 } else if ($charset == 'koi8-u') {
146 include_once(SM_PATH . 'functions/decode/koi8-u.php');
147 $ret = charset_decode_koi8u ($string);
148 } else if ($charset == 'windows-1250') {
149 include_once(SM_PATH . 'functions/decode/cp1250.php');
150 $ret = charset_decode_cp1250 ($string);
151 } else if ($charset == 'windows-1251') {
152 include_once(SM_PATH . 'functions/decode/cp1251.php');
153 $ret = charset_decode_cp1251 ($string);
154 } else if ($charset == 'windows-1252') {
155 include_once(SM_PATH . 'functions/decode/cp1252.php');
156 $ret = charset_decode_cp1252 ($string);
157 } else if ($charset == 'windows-1253') {
158 include_once(SM_PATH . 'functions/decode/cp1253.php');
159 $ret = charset_decode_cp1253 ($string);
160 } else if ($charset == 'windows-1254') {
161 include_once(SM_PATH . 'functions/decode/cp1254.php');
162 $ret = charset_decode_cp1254 ($string);
163 } else if ($charset == 'windows-1255') {
164 include_once(SM_PATH . 'functions/decode/cp1255.php');
165 $ret = charset_decode_cp1255 ($string);
166 } else if ($charset == 'windows-1256') {
167 include_once(SM_PATH . 'functions/decode/cp1256.php');
168 $ret = charset_decode_cp1256 ($string);
169 } else if ($charset == 'windows-1257') {
170 include_once(SM_PATH . 'functions/decode/cp1257.php');
171 $ret = charset_decode_cp1257 ($string);
172 } else if ($charset == 'windows-1258') {
173 include_once(SM_PATH . 'functions/decode/cp1258.php');
174 $ret = charset_decode_cp1258 ($string);
175 } else if ($charset == 'x-mac-roman') {
176 include_once(SM_PATH . 'functions/decode/cp10000.php');
177 $ret = charset_decode_cp10000 ($string);
178 } else if ($charset == 'x-mac-greek') {
179 include_once(SM_PATH . 'functions/decode/cp10006.php');
180 $ret = charset_decode_cp10006 ($string);
181 } else if ($charset == 'x-mac-cyrillic') {
182 include_once(SM_PATH . 'functions/decode/cp10007.php');
183 $ret = charset_decode_cp10007 ($string);
184 } else if ($charset == 'x-mac-ukrainian') {
185 include_once(SM_PATH . 'functions/decode/cp10017.php');
186 $ret = charset_decode_cp10017 ($string);
187 } else if ($charset == 'x-mac-centraleurroman') {
188 include_once(SM_PATH . 'functions/decode/cp10029.php');
189 $ret = charset_decode_cp10029 ($string);
190 } else if ($charset == 'x-mac-icelandic') {
191 include_once(SM_PATH . 'functions/decode/cp10079.php');
192 $ret = charset_decode_cp10079 ($string);
193 } else if ($charset == 'x-mac-turkish') {
194 include_once(SM_PATH . 'functions/decode/cp10081.php');
195 $ret = charset_decode_cp10081 ($string);
196 } else if ($charset == 'ibm855') {
197 include_once(SM_PATH . 'functions/decode/cp855.php');
198 $ret = charset_decode_cp855 ($string);
199 } else if ($charset == 'ibm866') {
200 include_once(SM_PATH . 'functions/decode/cp866.php');
201 $ret = charset_decode_cp866 ($string);
202 } else if ($charset == 'iso-ir-111') {
203 include_once(SM_PATH . 'functions/decode/iso-ir-111.php');
204 $ret = charset_decode_iso_ir_111 ($string);
205 } else if ($charset == 'tis-620') {
206 include_once(SM_PATH . 'functions/decode/tis620.php');
207 $ret = charset_decode_tis620 ($string);
208 } else if ($charset == 'big5' and $agresive_decoding ) {
209 include_once(SM_PATH . 'functions/decode/big5.php');
210 $ret = charset_decode_big5 ($string);
211 } else if ($charset == 'gb2312' and $agresive_decoding ) {
212 include_once(SM_PATH . 'functions/decode/gb2312.php');
213 $ret = charset_decode_gb2312 ($string);
214 } else if ($charset == 'utf-8' && $squirrelmail_language != 'ja_JP') {
215 include_once(SM_PATH . 'functions/decode/utf-8.php');
216 $ret = charset_decode_utf8 ($string);
217 } else {
218 $ret = $string;
219 }
220 return( $ret );
221 }
222
223
224 /* Remove all 8 bit characters from all other ISO-8859 character sets */
225 function charset_decode_iso_8859_default ($string) {
226 return (strtr($string, "\240\241\242\243\244\245\246\247".
227 "\250\251\252\253\254\255\256\257".
228 "\260\261\262\263\264\265\266\267".
229 "\270\271\272\273\274\275\276\277".
230 "\300\301\302\303\304\305\306\307".
231 "\310\311\312\313\314\315\316\317".
232 "\320\321\322\323\324\325\326\327".
233 "\330\331\332\333\334\335\336\337".
234 "\340\341\342\343\344\345\346\347".
235 "\350\351\352\353\354\355\356\357".
236 "\360\361\362\363\364\365\366\367".
237 "\370\371\372\373\374\375\376\377",
238 "????????????????????????????????????????".
239 "????????????????????????????????????????".
240 "????????????????????????????????????????".
241 "????????"));
242
243 }
244
245 /*
246 * This is the same as ISO-646-NO and is used by some
247 * Microsoft programs when sending Norwegian characters
248 */
249 function charset_decode_ns_4551_1 ($string) {
250 /*
251 * These characters are:
252 * Latin capital letter AE
253 * Latin capital letter O with stroke
254 * Latin capital letter A with ring above
255 * and the same as small letters
256 */
257 return strtr ($string, "[\\]{|}", "ÆØÅæøå");
258 }
259
260
261 /*
262 * Set up the language to be output
263 * if $do_search is true, then scan the browser information
264 * for a possible language that we know
265 */
266 function set_up_language($sm_language, $do_search = false, $default = false) {
267
268 static $SetupAlready = 0;
269 global $use_gettext, $languages,
270 $squirrelmail_language, $squirrelmail_default_language,
271 $sm_notAlias;
272
273 if ($SetupAlready) {
274 return;
275 }
276
277 $SetupAlready = TRUE;
278 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER);
279
280 if ($do_search && ! $sm_language && isset($accept_lang)) {
281 $sm_language = substr($accept_lang, 0, 2);
282 }
283
284 if ((!$sm_language||$default) && isset($squirrelmail_default_language)) {
285 $squirrelmail_language = $squirrelmail_default_language;
286 $sm_language = $squirrelmail_default_language;
287 }
288 $sm_notAlias = $sm_language;
289
290 // Catching removed translation
291 // System reverts to English translation if user prefs contain translation
292 // that is not available in $languages array (admin removed directory
293 // with that translation)
294 if (!isset($languages[$sm_notAlias])) {
295 $sm_notAlias="en_US";
296 }
297
298 while (isset($languages[$sm_notAlias]['ALIAS'])) {
299 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
300 }
301
302 if ( isset($sm_language) &&
303 $use_gettext &&
304 $sm_language != '' &&
305 isset($languages[$sm_notAlias]['CHARSET']) ) {
306 bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' );
307 textdomain( 'squirrelmail' );
308 if (function_exists('bind_textdomain_codeset')) {
309 if ($sm_notAlias == 'ja_JP') {
310 bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
311 } else {
312 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
313 }
314 }
315 if (isset($languages[$sm_notAlias]['LOCALE'])){
316 $longlocale=$languages[$sm_notAlias]['LOCALE'];
317 } else {
318 $longlocale=$sm_notAlias;
319 }
320 if ( !ini_get('safe_mode') &&
321 getenv( 'LC_ALL' ) != $longlocale ) {
322 putenv( "LC_ALL=$longlocale" );
323 putenv( "LANG=$longlocale" );
324 putenv( "LANGUAGE=$longlocale" );
325 }
326 setlocale(LC_ALL, $longlocale);
327 $squirrelmail_language = $sm_notAlias;
328 if ($squirrelmail_language == 'ja_JP') {
329 header ('Content-Type: text/html; charset=EUC-JP');
330 if (!function_exists('mb_internal_encoding')) {
331 echo _("You need to have php4 installed with the multibyte string function enabled (using configure option --enable-mbstring).");
332 // Revert to English link has to be added.
333 // stop further execution in order not to get php errors on mb_internal_encoding().
334 return;
335 }
336 if (function_exists('mb_language')) {
337 mb_language('Japanese');
338 }
339 mb_internal_encoding('EUC-JP');
340 mb_http_output('pass');
341 } else {
342 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
343 }
344 }
345 }
346
347 function set_my_charset(){
348
349 /*
350 * There can be a $default_charset setting in the
351 * config.php file, but the user may have a different language
352 * selected for a user interface. This function checks the
353 * language selected by the user and tags the outgoing messages
354 * with the appropriate charset corresponding to the language
355 * selection. This is "more right" (tm), than just stamping the
356 * message blindly with the system-wide $default_charset.
357 */
358 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
359
360 $my_language = getPref($data_dir, $username, 'language');
361 if (!$my_language) {
362 $my_language = $squirrelmail_default_language ;
363 }
364 // Catch removed translation
365 if (!isset($languages[$my_language])) {
366 $my_language="en_US";
367 }
368 while (isset($languages[$my_language]['ALIAS'])) {
369 $my_language = $languages[$my_language]['ALIAS'];
370 }
371 $my_charset = $languages[$my_language]['CHARSET'];
372 if ($my_charset) {
373 $default_charset = $my_charset;
374 }
375 }
376
377 /* ------------------------------ main --------------------------- */
378
379 global $squirrelmail_language, $languages, $use_gettext;
380
381 if (! isset($squirrelmail_language)) {
382 $squirrelmail_language = '';
383 }
384
385 /* This array specifies the available languages. */
386 $languages['bg_BG']['NAME'] = 'Bulgarian';
387 $languages['bg_BG']['ALTNAME'] = '&#1041;&#1098;&#1083;&#1075;&#1072;&#1088;&#1089;&#1082;&#1080;';
388 $languages['bg_BG']['CHARSET'] = 'windows-1251';
389 $languages['bg']['ALIAS'] = 'bg_BG';
390
391 $languages['ca_ES']['NAME'] = 'Catalan';
392 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
393 $languages['ca']['ALIAS'] = 'ca_ES';
394
395 $languages['cs_CZ']['NAME'] = 'Czech';
396 $languages['cs_CZ']['ALTNAME'] = '&#268;e&scaron;tina';
397 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
398 $languages['cs']['ALIAS'] = 'cs_CZ';
399
400 $languages['cy_GB']['NAME'] = 'Welsh';
401 $languages['cy_GB']['ALTNAME'] = 'Cymraeg';
402 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
403 $languages['cy']['ALIAS'] = 'cy_GB';
404
405 // Danish locale is da_DK.
406 $languages['da_DK']['NAME'] = 'Danish';
407 $languages['da_DK']['ALTNAME'] = 'Dansk';
408 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
409 $languages['da']['ALIAS'] = 'da_DK';
410
411 $languages['de_DE']['NAME'] = 'German';
412 $languages['de_DE']['ALTNAME'] = 'Deutsch';
413 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
414 $languages['de']['ALIAS'] = 'de_DE';
415
416 $languages['el_GR']['NAME'] = 'Greek';
417 $languages['el_GR']['ALTNAME'] = '&Epsilon;&lambda;&lambda;&eta;&nu;&iota;&kappa;&#940;';
418 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
419 $languages['el']['ALIAS'] = 'el_GR';
420
421 // There is no en_EN! There is en_US, en_BR, en_AU, and so forth,
422 // but who cares about !US, right? Right? :)
423 $languages['en_US']['NAME'] = 'English';
424 $languages['en_US']['CHARSET'] = 'iso-8859-1';
425 $languages['en']['ALIAS'] = 'en_US';
426
427 $languages['es_ES']['NAME'] = 'Spanish';
428 $languages['es_ES']['ALTNAME'] = 'Espa&ntilde;ol';
429 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
430 $languages['es']['ALIAS'] = 'es_ES';
431
432 $languages['et_EE']['NAME'] = 'Estonian';
433 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
434 $languages['et']['ALIAS'] = 'et_EE';
435
436 $languages['fo_FO']['NAME'] = 'Faroese';
437 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
438 $languages['fo']['ALIAS'] = 'fo_FO';
439
440 $languages['fi_FI']['NAME'] = 'Finnish';
441 $languages['fi_FI']['ALTNAME'] = 'Suomi';
442 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
443 $languages['fi']['ALIAS'] = 'fi_FI';
444
445 $languages['fr_FR']['NAME'] = 'French';
446 $languages['fr_FR']['ALTNAME'] = 'Fran&#231;ais';
447 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
448 $languages['fr']['ALIAS'] = 'fr_FR';
449
450 $languages['hr_HR']['NAME'] = 'Croatian';
451 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
452 $languages['hr']['ALIAS'] = 'hr_HR';
453
454 $languages['hu_HU']['NAME'] = 'Hungarian';
455 $languages['hu_HU']['ALTNAME'] = 'Magyar';
456 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
457 $languages['hu']['ALIAS'] = 'hu_HU';
458
459 $languages['id_ID']['NAME'] = 'Indonesian';
460 $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
461 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
462 $languages['id']['ALIAS'] = 'id_ID';
463
464 $languages['is_IS']['NAME'] = 'Icelandic';
465 $languages['is_IS']['ALTNAME'] = '&Iacute;slenska';
466 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
467 $languages['is']['ALIAS'] = 'is_IS';
468
469 $languages['it_IT']['NAME'] = 'Italian';
470 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
471 $languages['it']['ALIAS'] = 'it_IT';
472
473 $languages['ja_JP']['NAME'] = 'Japanese';
474 $languages['ja_JP']['ALTNAME'] = '&#26085;&#26412;&#35486;';
475 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
476 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
477 $languages['ja']['ALIAS'] = 'ja_JP';
478
479 $languages['ko_KR']['NAME'] = 'Korean';
480 $languages['ko_KR']['CHARSET'] = 'euc-KR';
481 $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
482 $languages['ko']['ALIAS'] = 'ko_KR';
483
484 $languages['lt_LT']['NAME'] = 'Lithuanian';
485 $languages['lt_LT']['ALTNAME'] = 'Lietuvi&#371;';
486 $languages['lt_LT']['CHARSET'] = 'utf-8';
487 $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
488 $languages['lt']['ALIAS'] = 'lt_LT';
489
490 $languages['nl_NL']['NAME'] = 'Dutch';
491 $languages['nl_NL']['ALTNAME'] = 'Nederlands';
492 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
493 $languages['nl']['ALIAS'] = 'nl_NL';
494
495 $languages['ms_MY']['NAME'] = 'Malay';
496 $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
497 $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
498 $languages['my']['ALIAS'] = 'ms_MY';
499
500 $languages['no_NO']['NAME'] = 'Norwegian (Bokm&aring;l)';
501 $languages['no_NO']['ALTNAME'] = 'Norsk (Bokm&aring;l)';
502 $languages['no_NO']['CHARSET'] = 'iso-8859-1';
503 $languages['no']['ALIAS'] = 'no_NO';
504
505 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
506 $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
507 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
508
509 $languages['pl_PL']['NAME'] = 'Polish';
510 $languages['pl_PL']['ALTNAME'] = 'Polski';
511 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
512 $languages['pl']['ALIAS'] = 'pl_PL';
513
514 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
515 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
516 $languages['pt']['ALIAS'] = 'pt_PT';
517
518 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
519 $languages['pt_BR']['ALTNAME'] = 'Portugu&ecirc;s do Brasil';
520 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
521
522 $languages['ro_RO']['NAME'] = 'Romanian';
523 $languages['ro_RO']['ALTNAME'] = 'Rom&acirc;n&#259;';
524 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
525 $languages['ro']['ALIAS'] = 'ro_RO';
526
527 $languages['ru_RU']['NAME'] = 'Russian';
528 $languages['ru_RU']['ALTNAME'] = '&#1056;&#1091;&#1089;&#1089;&#1082;&#1080;&#1081;';
529 $languages['ru_RU']['CHARSET'] = 'utf-8';
530 $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
531 $languages['ru']['ALIAS'] = 'ru_RU';
532
533 $languages['sk_SK']['NAME'] = 'Slovak';
534 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
535 $languages['sk']['ALIAS'] = 'sk_SK';
536
537 $languages['sl_SI']['NAME'] = 'Slovenian';
538 $languages['sl_SI']['ALTNAME'] = 'Sloven&scaron;&#269;ina';
539 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
540 $languages['sl']['ALIAS'] = 'sl_SI';
541
542 $languages['sr_YU']['NAME'] = 'Serbian';
543 $languages['sr_YU']['ALTNAME'] = 'Srpski';
544 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
545 $languages['sr']['ALIAS'] = 'sr_YU';
546
547 $languages['sv_SE']['NAME'] = 'Swedish';
548 $languages['sv_SE']['ALTNAME'] = 'Svenska';
549 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
550 $languages['sv']['ALIAS'] = 'sv_SE';
551
552 $languages['th_TH']['NAME'] = 'Thai';
553 $languages['th_TH']['CHARSET'] = 'tis-620';
554 $languages['th']['ALIAS'] = 'th_TH';
555
556 $languages['tr_TR']['NAME'] = 'Turkish';
557 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
558 $languages['tr']['ALIAS'] = 'tr_TR';
559
560 $languages['zh_TW']['NAME'] = 'Chinese Trad';
561 $languages['zh_TW']['CHARSET'] = 'big5';
562 $languages['tw']['ALIAS'] = 'zh_TW';
563
564 $languages['zh_CN']['NAME'] = 'Chinese Simp';
565 $languages['zh_CN']['CHARSET'] = 'gb2312';
566 $languages['cn']['ALIAS'] = 'zh_CN';
567
568 /*
569 $languages['uk_UA']['NAME'] = 'Ukrainian';
570 $languages['uk_UA']['CHARSET'] = 'koi8-u';
571 $languages['uk']['ALIAS'] = 'uk_UA';
572 */
573 /*
574 if ( file_exists( SM_PATH . 'locale/vi_VN') ) {
575 $languages['vi_VN']['NAME'] = 'Vietnamese';
576 $languages['vi_VN']['CHARSET'] = 'utf-8';
577 $languages['vi']['ALIAS'] = 'vi_VN';
578 }
579 */
580
581 // Right to left languages
582 $languages['ar']['NAME'] = 'Arabic';
583 $languages['ar']['CHARSET'] = 'windows-1256';
584 $languages['ar']['DIR'] = 'rtl';
585
586 $languages['he_IL']['NAME'] = 'Hebrew';
587 $languages['he_IL']['CHARSET'] = 'windows-1255';
588 $languages['he_IL']['DIR'] = 'rtl';
589 $languages['he']['ALIAS'] = 'he_IL';
590
591 /* Detect whether gettext is installed. */
592 $gettext_flags = 0;
593 if (function_exists('_')) {
594 $gettext_flags += 1;
595 }
596 if (function_exists('bindtextdomain')) {
597 $gettext_flags += 2;
598 }
599 if (function_exists('textdomain')) {
600 $gettext_flags += 4;
601 }
602
603 /* If gettext is fully loaded, cool */
604 if ($gettext_flags == 7) {
605 $use_gettext = true;
606 }
607 /* If we can fake gettext, try that */
608 elseif ($gettext_flags == 0) {
609 $use_gettext = true;
610 include_once(SM_PATH . 'functions/gettext.php');
611 } else {
612 /* Uh-ho. A weird install */
613 if (! $gettext_flags & 1) {
614 function _($str) {
615 return $str;
616 }
617 }
618 if (! $gettext_flags & 2) {
619 function bindtextdomain() {
620 return;
621 }
622 }
623 if (! $gettext_flags & 4) {
624 function textdomain() {
625 return;
626 }
627 }
628 }
629
630
631 /*
632 * Japanese charset extra function
633 *
634 */
635 function japanese_charset_xtra() {
636 $ret = func_get_arg(1); /* default return value */
637 if (function_exists('mb_detect_encoding')) {
638 switch (func_get_arg(0)) { /* action */
639 case 'decode':
640 $detect_encoding = @mb_detect_encoding($ret);
641 if ($detect_encoding == 'JIS' ||
642 $detect_encoding == 'EUC-JP' ||
643 $detect_encoding == 'SJIS' ||
644 $detect_encoding == 'UTF-8') {
645
646 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
647 }
648 break;
649 case 'encode':
650 $detect_encoding = @mb_detect_encoding($ret);
651 if ($detect_encoding == 'JIS' ||
652 $detect_encoding == 'EUC-JP' ||
653 $detect_encoding == 'SJIS' ||
654 $detect_encoding == 'UTF-8') {
655
656 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
657 }
658 break;
659 case 'strimwidth':
660 $width = func_get_arg(2);
661 $ret = mb_strimwidth($ret, 0, $width, '...');
662 break;
663 case 'encodeheader':
664 $result = '';
665 if (strlen($ret) > 0) {
666 $tmpstr = mb_substr($ret, 0, 1);
667 $prevcsize = strlen($tmpstr);
668 for ($i = 1; $i < mb_strlen($ret); $i++) {
669 $tmp = mb_substr($ret, $i, 1);
670 if (strlen($tmp) == $prevcsize) {
671 $tmpstr .= $tmp;
672 } else {
673 if ($prevcsize == 1) {
674 $result .= $tmpstr;
675 } else {
676 $result .= str_replace(' ', '',
677 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
678 }
679 $tmpstr = $tmp;
680 $prevcsize = strlen($tmp);
681 }
682 }
683 if (strlen($tmpstr)) {
684 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
685 $result .= $tmpstr;
686 else
687 $result .= str_replace(' ', '',
688 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
689 }
690 }
691 $ret = $result;
692 break;
693 case 'decodeheader':
694 $ret = str_replace("\t", "", $ret);
695 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
696 $ret = @mb_decode_mimeheader($ret);
697 $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
698 break;
699 case 'downloadfilename':
700 $useragent = func_get_arg(2);
701 if (strstr($useragent, 'Windows') !== false ||
702 strstr($useragent, 'Mac_') !== false) {
703 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
704 } else {
705 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
706 }
707 break;
708 case 'wordwrap':
709 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
710 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
711 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
712 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
713 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
714 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
715 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
716 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
717 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
718 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
719 $wrap = func_get_arg(2);
720
721 if (strlen($ret) >= $wrap &&
722 substr($ret, 0, 1) != '>' &&
723 strpos($ret, 'http://') === FALSE &&
724 strpos($ret, 'https://') === FALSE &&
725 strpos($ret, 'ftp://') === FALSE) {
726
727 $ret = mb_convert_kana($ret, "KV");
728
729 $line_new = '';
730 $ptr = 0;
731
732 while ($ptr < strlen($ret) - 1) {
733 $l = mb_strcut($ret, $ptr, $wrap);
734 $ptr += strlen($l);
735 $tmp = $l;
736
737 $l = mb_strcut($ret, $ptr, 2);
738 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
739 $tmp .= $l;
740 $ptr += strlen($l);
741 $l = mb_strcut($ret, $ptr, 1);
742 }
743 $line_new .= $tmp;
744 if ($ptr < strlen($ret) - 1)
745 $line_new .= "\n";
746 }
747 $ret = $line_new;
748 }
749 break;
750 case 'utf7-imap_encode':
751 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
752 break;
753 case 'utf7-imap_decode':
754 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
755 break;
756 }
757 }
758 return $ret;
759 }
760
761
762 /*
763 * Korean charset extra function
764 * Hangul(Korean Character) Attached File Name Fix.
765 */
766 function korean_charset_xtra() {
767
768 $ret = func_get_arg(1); /* default return value */
769 if (func_get_arg(0) == 'downloadfilename') { /* action */
770 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
771 for ($i=0;$i<strlen($ret);$i++) {
772 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
773 $i++;
774 continue;
775 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */
776 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
777 ($ret[$i] == '.') || ($ret[$i] == '-')) {
778 continue;
779 } else {
780 $ret[$i] = '_';
781 }
782 }
783
784 }
785
786 return $ret;
787 }
788
789 /**
790 * Replaces non-braking spaces inserted by some browsers with regular space
791 *
792 * This function can be used to replace non-braking space symbols
793 * that are inserted in forms by some browsers instead of normal
794 * space symbol.
795 *
796 * @param string $string Text that needs to be cleaned
797 * @param string $charset Charset used in text
798 * @return string Cleaned text
799 */
800 function cleanup_nbsp($string,$charset) {
801
802 // reduce number of case statements
803 if (stristr('iso-8859-',substr($charset,0,9))){
804 $output_charset="iso-8859-x";
805 }
806 if (stristr('windows-125',substr($charset,0,11))){
807 $output_charset="cp125x";
808 }
809 if (stristr('koi8',substr($charset,0,4))){
810 $output_charset="koi8-x";
811 }
812 if (! isset($output_charset)){
813 $output_charset=strtolower($charset);
814 }
815
816 // where is non-braking space symbol
817 switch($output_charset):
818 case "iso-8859-x":
819 case "cp125x":
820 case "iso-2022-jp":
821 $nbsp="\xA0";
822 break;
823 case "koi8-x":
824 $nbsp="\x9A";
825 break;
826 case "utf-8":
827 $nbsp="\xC2\xA0";
828 break;
829 default:
830 // don't change string if charset is unmatched
831 return $string;
832 endswitch;
833
834 // return space instead of non-braking space.
835 return str_replace($nbsp,' ',$string);
836 }
837
838 /**
839 * Function informs if it is safe to convert given charset to the one that is used by user.
840 *
841 * It is safe to use conversion only if user uses utf-8 encoding and when
842 * converted charset is similar to the one that is used by user.
843 *
844 * @param string $input_charset Charset of text that needs to be converted
845 * @return bool is it possible to convert to user's charset
846 */
847 function is_conversion_safe($input_charset) {
848 global $languages, $sm_notAlias, $default_charset;
849
850 // convert to lower case
851 $input_charset = strtolower($input_charset);
852
853 // Is user's locale Unicode based ?
854 if ( $default_charset == "utf-8" ) {
855 return true;
856 }
857
858 // Charsets that are similar
859 switch ($default_charset):
860 case "windows-1251":
861 if ( $input_charset == "iso-8859-5" ||
862 $input_charset == "koi8-r" ||
863 $input_charset == "koi8-u" ) {
864 return true;
865 } else {
866 return false;
867 }
868 case "windows-1257":
869 if ( $input_charset == "iso-8859-13" ||
870 $input_charset == "iso-8859-4" ) {
871 return true;
872 } else {
873 return false;
874 }
875 case "iso-8859-4":
876 if ( $input_charset == "iso-8859-13" ||
877 $input_charset == "windows-1257" ) {
878 return true;
879 } else {
880 return false;
881 }
882 case "iso-8859-5":
883 if ( $input_charset == "windows-1251" ||
884 $input_charset == "koi8-r" ||
885 $input_charset == "koi8-u" ) {
886 return true;
887 } else {
888 return false;
889 }
890 case "iso-8859-13":
891 if ( $input_charset == "iso-8859-4" ||
892 $input_charset == "windows-1257" ) {
893 return true;
894 } else {
895 return false;
896 }
897 case "koi8-r":
898 if ( $input_charset == "windows-1251" ||
899 $input_charset == "iso-8859-5" ||
900 $input_charset == "koi8-u" ) {
901 return true;
902 } else {
903 return false;
904 }
905 case "koi8-u":
906 if ( $input_charset == "windows-1251" ||
907 $input_charset == "iso-8859-5" ||
908 $input_charset == "koi8-r" ) {
909 return true;
910 } else {
911 return false;
912 }
913 default:
914 return false;
915 endswitch;
916 }
917 ?>