77a6abe61a399898d829ffe47569efb6011867be
4 * SquirrelMail internationalization functions
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file contains variuos functions that are needed to do
10 * internationalization of SquirrelMail.
12 * Internally the output character set is used. Other characters are
13 * encoded using Unicode entities according to HTML 4.0.
16 * @package squirrelmail
20 /** Everything uses global.php... */
21 require_once(SM_PATH
. 'functions/global.php');
24 * Converts string from given charset to charset, that can be displayed by user translation.
26 * Function by default returns html encoded strings, if translation uses different encoding.
27 * If Japanese translation is used - function returns string converted to euc-jp
28 * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string.
29 * If $charset is not supported - function returns unconverted string.
31 * sanitizing of html tags is also done by this function.
33 * @param string $charset
34 * @param string $string Text to be decoded
35 * @return string decoded string
37 function charset_decode ($charset, $string) {
38 global $languages, $squirrelmail_language, $default_charset;
39 global $use_php_recode, $use_php_iconv, $agresive_decoding;
41 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
42 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
43 $string = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $string);
46 $charset = strtolower($charset);
50 // Variables that allow to use functions without function_exist() calls
51 if (! isset($use_php_recode) ||
$use_php_recode=="" ) {
52 $use_php_recode=false; }
53 if (! isset($use_php_iconv) ||
$use_php_iconv=="" ) {
54 $use_php_iconv=false; }
56 // Don't do conversion if charset is the same.
57 if ( $charset == strtolower($default_charset) )
58 return htmlspecialchars($string);
60 // catch iso-8859-8-i thing
61 if ( $charset == "iso-8859-8-i" )
62 $charset = "iso-8859-8";
65 * Recode converts html special characters automatically if you use
66 * 'charset..html' decoding. There is no documented way to put -d option
67 * into php recode function call.
69 if ( $use_php_recode ) {
70 if ( $default_charset == "utf-8" ) {
71 // other charsets can be converted to utf-8 without loss.
72 // and output string is smaller
73 $string = recode_string($charset . "..utf-8",$string);
74 return htmlspecialchars($string);
76 $string = recode_string($charset . "..html",$string);
77 // recode does not convert single quote, htmlspecialchars does.
78 $string = str_replace("'", ''', $string);
83 // iconv functions does not have html target and can be used only with utf-8
84 if ( $use_php_iconv && $default_charset=='utf-8') {
85 $string = iconv($charset,$default_charset,$string);
86 return htmlspecialchars($string);
89 // If we don't use recode and iconv, we'll do it old way.
91 /* All HTML special characters are 7 bit and can be replaced first */
93 $string = htmlspecialchars ($string);
95 /* controls cpu and memory intensive decoding cycles */
96 if (! isset($agresive_decoding) ||
$agresive_decoding=="" ) {
97 $agresive_decoding=false; }
99 $decode=fixcharset($charset);
100 $decodefile=SM_PATH
. 'functions/decode/' . $decode . '.php';
101 if (file_exists($decodefile)) {
102 include_once($decodefile);
103 $ret = call_user_func('charset_decode_'.$decode, $string);
111 * Converts html string to given charset
112 * @param string $string
113 * @param string $charset
116 function charset_encode($string,$charset) {
117 global $default_charset;
119 $encode=fixcharset($charset);
120 $encodefile=SM_PATH
. 'functions/encode/' . $encode . '.php';
121 if (file_exists($encodefile)) {
122 include_once($encodefile);
123 $ret = call_user_func('charset_encode_'.$encode, $string);
131 * Combined decoding and encoding functions
133 * If conversion is done to charset different that utf-8, unsupported symbols
134 * will be replaced with question marks.
135 * @param string $in_charset initial charset
136 * @param string $string string that has to be converted
137 * @param string $out_charset final charset
138 * @return string converted string
140 function charset_convert($in_charset,$string,$out_charset) {
141 $string=charset_decode($in_charset,$string);
142 $string=charset_encode($string,$out_charset);
147 * Makes charset name suitable for decoding cycles
149 * @param string $charset Name of charset
150 * @return string $charset Adjusted name of charset
152 function fixcharset($charset) {
153 // minus removed from function names
154 $charset=str_replace('-','_',$charset);
156 // windows-125x and cp125x charsets
157 $charset=str_replace('windows_','cp',$charset);
160 $charset=str_replace('ibm','cp',$charset);
162 // iso-8859-8-i -> iso-8859-8
163 // use same cycle until I'll find differences
164 $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset);
170 * Set up the language to be output
171 * if $do_search is true, then scan the browser information
172 * for a possible language that we know
174 * Function sets system locale environment (LC_ALL, LANG, LANGUAGE),
175 * gettext translation bindings and html header information.
177 * Function returns error codes, if there is some fatal error.
179 * 1 = mbstring support is not present,
180 * 2 = mbstring support is not present, user's translation reverted to en_US.
182 * @param string $sm_language translation used by user's interface
183 * @param bool $do_search use browser's preferred language detection functions. Defaults to false.
184 * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false.
185 * @return int function execution error codes.
187 function set_up_language($sm_language, $do_search = false, $default = false) {
189 static $SetupAlready = 0;
190 global $use_gettext, $languages,
191 $squirrelmail_language, $squirrelmail_default_language,
192 $sm_notAlias, $username, $data_dir;
198 $SetupAlready = TRUE;
199 sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER
);
201 if ($do_search && ! $sm_language && isset($accept_lang)) {
202 $sm_language = substr($accept_lang, 0, 2);
205 if ((!$sm_language||
$default) && isset($squirrelmail_default_language)) {
206 $squirrelmail_language = $squirrelmail_default_language;
207 $sm_language = $squirrelmail_default_language;
209 $sm_notAlias = $sm_language;
211 // Catching removed translation
212 // System reverts to English translation if user prefs contain translation
213 // that is not available in $languages array
214 if (!isset($languages[$sm_notAlias])) {
215 $sm_notAlias="en_US";
218 while (isset($languages[$sm_notAlias]['ALIAS'])) {
219 $sm_notAlias = $languages[$sm_notAlias]['ALIAS'];
222 if ( isset($sm_language) &&
224 $sm_language != '' &&
225 isset($languages[$sm_notAlias]['CHARSET']) ) {
226 bindtextdomain( 'squirrelmail', SM_PATH
. 'locale/' );
227 textdomain( 'squirrelmail' );
228 if (function_exists('bind_textdomain_codeset')) {
229 if ($sm_notAlias == 'ja_JP') {
230 bind_textdomain_codeset ("squirrelmail", 'EUC-JP');
232 bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] );
235 if (isset($languages[$sm_notAlias]['LOCALE'])){
236 $longlocale=$languages[$sm_notAlias]['LOCALE'];
238 $longlocale=$sm_notAlias;
240 if ( !ini_get('safe_mode') &&
241 getenv( 'LC_ALL' ) != $longlocale ) {
242 putenv( "LC_ALL=$longlocale" );
243 putenv( "LANG=$longlocale" );
244 putenv( "LANGUAGE=$longlocale" );
246 setlocale(LC_ALL
, $longlocale);
248 // Set text direction/alignment variables
249 if (isset($languages[$sm_notAlias]['DIR']) &&
250 $languages[$sm_notAlias]['DIR'] == 'rtl') {
253 * @global string $text_direction
255 $text_direction='rtl';
258 * @global string $left_align
263 * @global string $right_align
267 $text_direction='ltr';
269 $right_align='right';
272 $squirrelmail_language = $sm_notAlias;
273 if ($squirrelmail_language == 'ja_JP') {
274 header ('Content-Type: text/html; charset=EUC-JP');
275 if (!function_exists('mb_internal_encoding')) {
276 // Error messages can't be displayed here
278 // Revert to English if possible.
279 if (function_exists('setPref') && $username!='' && $data_dir!="") {
280 setPref($data_dir, $username, 'language', "en_US");
283 // stop further execution in order not to get php errors on mb_internal_encoding().
286 if (function_exists('mb_language')) {
287 mb_language('Japanese');
289 mb_internal_encoding('EUC-JP');
290 mb_http_output('pass');
292 header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] );
299 * Sets default_charset variable according to the one that is used by user's translations.
301 * Function changes global $default_charset variable in order to be sure, that it
302 * contains charset used by user's translation. Sanity of $squirrelmail_default_language
303 * and $default_charset combination provided in SquirrelMail config is also tested.
305 * There can be a $default_charset setting in the
306 * config.php file, but the user may have a different language
307 * selected for a user interface. This function checks the
308 * language selected by the user and tags the outgoing messages
309 * with the appropriate charset corresponding to the language
310 * selection. This is "more right" (tm), than just stamping the
311 * message blindly with the system-wide $default_charset.
313 function set_my_charset(){
314 global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language;
316 $my_language = getPref($data_dir, $username, 'language');
318 $my_language = $squirrelmail_default_language ;
320 // Catch removed translation
321 if (!isset($languages[$my_language])) {
322 $my_language="en_US";
324 while (isset($languages[$my_language]['ALIAS'])) {
325 $my_language = $languages[$my_language]['ALIAS'];
327 $my_charset = $languages[$my_language]['CHARSET'];
329 $default_charset = $my_charset;
333 /* ------------------------------ main --------------------------- */
335 global $squirrelmail_language, $languages, $use_gettext;
337 if (! isset($squirrelmail_language)) {
338 $squirrelmail_language = '';
342 * Array specifies the available translations.
344 * Structure of array:
345 * $languages['language']['variable'] = 'value'
347 * Possible 'variable' names:
348 * NAME - Translation name in English
349 * CHARSET - Encoding used by translation
350 * ALIAS - used when 'language' is only short name and 'value' should provide long language name
351 * ALTNAME - Native translation name. Any 8bit symbols must be html encoded.
352 * LOCALE - Full locale name (in xx_XX.charset format)
353 * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr'
354 * XTRA_CODE - translation uses special functions. 'value' provides name of that extra function
356 * Each 'language' definition requires NAME+CHARSET or ALIAS variables.
359 * @global array $languages
361 $languages['bg_BG']['NAME'] = 'Bulgarian';
362 $languages['bg_BG']['ALTNAME'] = 'Български';
363 $languages['bg_BG']['CHARSET'] = 'windows-1251';
364 $languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251';
365 $languages['bg']['ALIAS'] = 'bg_BG';
367 $languages['ca_ES']['NAME'] = 'Catalan';
368 $languages['ca_ES']['CHARSET'] = 'iso-8859-1';
369 $languages['ca_ES']['LOCALE'] = 'ca_ES.ISO8859-1';
370 $languages['ca']['ALIAS'] = 'ca_ES';
372 $languages['cs_CZ']['NAME'] = 'Czech';
373 $languages['cs_CZ']['ALTNAME'] = 'Čeština';
374 $languages['cs_CZ']['CHARSET'] = 'iso-8859-2';
375 $languages['cs_CZ']['LOCALE'] = 'cs_CZ.ISO8859-2';
376 $languages['cs']['ALIAS'] = 'cs_CZ';
378 $languages['cy_GB']['NAME'] = 'Welsh';
379 $languages['cy_GB']['ALTNAME'] = 'Cymraeg';
380 $languages['cy_GB']['CHARSET'] = 'iso-8859-1';
381 $languages['cy_GB']['LOCALE'] = 'cy_GB.ISO8859-1';
382 $languages['cy']['ALIAS'] = 'cy_GB';
384 // Danish locale is da_DK.
385 $languages['da_DK']['NAME'] = 'Danish';
386 $languages['da_DK']['ALTNAME'] = 'Dansk';
387 $languages['da_DK']['CHARSET'] = 'iso-8859-1';
388 $languages['da_DK']['LOCALE'] = 'da_DK.ISO8859-1';
389 $languages['da']['ALIAS'] = 'da_DK';
391 $languages['de_DE']['NAME'] = 'German';
392 $languages['de_DE']['ALTNAME'] = 'Deutsch';
393 $languages['de_DE']['CHARSET'] = 'iso-8859-1';
394 $languages['de_DE']['LOCALE'] = 'de_DE.ISO8859-1';
395 $languages['de']['ALIAS'] = 'de_DE';
397 $languages['el_GR']['NAME'] = 'Greek';
398 $languages['el_GR']['ALTNAME'] = 'Ελληνικά';
399 $languages['el_GR']['CHARSET'] = 'iso-8859-7';
400 $languages['el_GR']['LOCALE'] = 'el_GR.ISO8859-7';
401 $languages['el']['ALIAS'] = 'el_GR';
403 $languages['en_GB']['NAME'] = 'British';
404 $languages['en_GB']['CHARSET'] = 'iso-8859-15';
405 $languages['en_GB']['LOCALE'] = 'en_GB.ISO8859-15';
407 $languages['en_US']['NAME'] = 'English';
408 $languages['en_US']['CHARSET'] = 'iso-8859-1';
409 $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1';
410 $languages['en']['ALIAS'] = 'en_US';
412 $languages['es_ES']['NAME'] = 'Spanish';
413 $languages['es_ES']['ALTNAME'] = 'Español';
414 $languages['es_ES']['CHARSET'] = 'iso-8859-1';
415 $languages['es_ES']['LOCALE'] = 'es_ES.ISO8859-1';
416 $languages['es']['ALIAS'] = 'es_ES';
418 $languages['et_EE']['NAME'] = 'Estonian';
419 $languages['et_EE']['CHARSET'] = 'iso-8859-15';
420 $languages['et_EE']['LOCALE'] = 'et_EE.ISO8859-15';
421 $languages['et']['ALIAS'] = 'et_EE';
423 $languages['fo_FO']['NAME'] = 'Faroese';
424 $languages['fo_FO']['CHARSET'] = 'iso-8859-1';
425 $languages['fo_FO']['LOCALE'] = 'fo_FO.ISO8859-1';
426 $languages['fo']['ALIAS'] = 'fo_FO';
428 $languages['fi_FI']['NAME'] = 'Finnish';
429 $languages['fi_FI']['ALTNAME'] = 'Suomi';
430 $languages['fi_FI']['CHARSET'] = 'iso-8859-1';
431 $languages['fi_FI']['LOCALE'] = 'fi_FI.ISO8859-1';
432 $languages['fi']['ALIAS'] = 'fi_FI';
434 $languages['fr_FR']['NAME'] = 'French';
435 $languages['fr_FR']['ALTNAME'] = 'Français';
436 $languages['fr_FR']['CHARSET'] = 'iso-8859-1';
437 $languages['fr_FR']['LOCALE'] = 'fr_FR.ISO8859-1';
438 $languages['fr']['ALIAS'] = 'fr_FR';
440 $languages['hr_HR']['NAME'] = 'Croatian';
441 $languages['hr_HR']['CHARSET'] = 'iso-8859-2';
442 $languages['hr_HR']['LOCALE'] = 'hr_HR.ISO8859-2';
443 $languages['hr']['ALIAS'] = 'hr_HR';
445 $languages['hu_HU']['NAME'] = 'Hungarian';
446 $languages['hu_HU']['ALTNAME'] = 'Magyar';
447 $languages['hu_HU']['CHARSET'] = 'iso-8859-2';
448 $languages['hu_HU']['LOCALE'] = 'hu_HU.ISO8859-2';
449 $languages['hu']['ALIAS'] = 'hu_HU';
451 $languages['id_ID']['NAME'] = 'Indonesian';
452 $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia';
453 $languages['id_ID']['CHARSET'] = 'iso-8859-1';
454 $languages['id_ID']['LOCALE'] = 'id_ID.ISO8859-1';
455 $languages['id']['ALIAS'] = 'id_ID';
457 $languages['is_IS']['NAME'] = 'Icelandic';
458 $languages['is_IS']['ALTNAME'] = 'Íslenska';
459 $languages['is_IS']['CHARSET'] = 'iso-8859-1';
460 $languages['is_IS']['LOCALE'] = 'is_IS.ISO8859-1';
461 $languages['is']['ALIAS'] = 'is_IS';
463 $languages['it_IT']['NAME'] = 'Italian';
464 $languages['it_IT']['CHARSET'] = 'iso-8859-1';
465 $languages['it_IT']['LOCALE'] = 'it_IT.ISO8859-1';
466 $languages['it']['ALIAS'] = 'it_IT';
468 $languages['ja_JP']['NAME'] = 'Japanese';
469 $languages['ja_JP']['ALTNAME'] = '日本語';
470 $languages['ja_JP']['CHARSET'] = 'iso-2022-jp';
471 $languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP';
472 $languages['ja_JP']['XTRA_CODE'] = 'japanese_charset_xtra';
473 $languages['ja']['ALIAS'] = 'ja_JP';
475 $languages['ko_KR']['NAME'] = 'Korean';
476 $languages['ko_KR']['CHARSET'] = 'euc-KR';
477 $languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR';
478 // Function does not provide all needed options
479 // $languages['ko_KR']['XTRA_CODE'] = 'korean_charset_xtra';
480 $languages['ko']['ALIAS'] = 'ko_KR';
482 $languages['lt_LT']['NAME'] = 'Lithuanian';
483 $languages['lt_LT']['ALTNAME'] = 'Lietuvių';
484 $languages['lt_LT']['CHARSET'] = 'utf-8';
485 $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8';
486 $languages['lt']['ALIAS'] = 'lt_LT';
488 $languages['nl_NL']['NAME'] = 'Dutch';
489 $languages['nl_NL']['ALTNAME'] = 'Nederlands';
490 $languages['nl_NL']['CHARSET'] = 'iso-8859-1';
491 $languages['nl_NL']['LOCALE'] = 'nl_NL.ISO8859-1';
492 $languages['nl']['ALIAS'] = 'nl_NL';
494 $languages['ms_MY']['NAME'] = 'Malay';
495 $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu';
496 $languages['ms_MY']['CHARSET'] = 'iso-8859-1';
497 $languages['ms_MY']['LOCALE'] = 'ms_MY.ISO8859-1';
498 $languages['my']['ALIAS'] = 'ms_MY';
500 $languages['nb_NO']['NAME'] = 'Norwegian (Bokmål)';
501 $languages['nb_NO']['ALTNAME'] = 'Norsk (Bokmål)';
502 $languages['nb_NO']['CHARSET'] = 'iso-8859-1';
503 $languages['nb_NO']['LOCALE'] = 'nb_NO.ISO8859-1';
504 $languages['nb']['ALIAS'] = 'nb_NO';
506 $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)';
507 $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)';
508 $languages['nn_NO']['CHARSET'] = 'iso-8859-1';
509 $languages['nn_NO']['LOCALE'] = 'nn_NO.ISO8859-1';
511 $languages['pl_PL']['NAME'] = 'Polish';
512 $languages['pl_PL']['ALTNAME'] = 'Polski';
513 $languages['pl_PL']['CHARSET'] = 'iso-8859-2';
514 $languages['pl_PL']['LOCALE'] = 'pl_PL.ISO8859-2';
515 $languages['pl']['ALIAS'] = 'pl_PL';
517 $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)';
518 $languages['pt_PT']['CHARSET'] = 'iso-8859-1';
519 $languages['pt_PT']['LOCALE'] = 'pt_PT.ISO8859-1';
520 $languages['pt']['ALIAS'] = 'pt_PT';
522 $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)';
523 $languages['pt_BR']['ALTNAME'] = 'Português do Brasil';
524 $languages['pt_BR']['CHARSET'] = 'iso-8859-1';
525 $languages['pt_BR']['LOCALE'] = 'pt_BR.ISO8859-1';
527 $languages['ro_RO']['NAME'] = 'Romanian';
528 $languages['ro_RO']['ALTNAME'] = 'Română';
529 $languages['ro_RO']['CHARSET'] = 'iso-8859-2';
530 $languages['ro_RO']['LOCALE'] = 'ro_RO.ISO8859-2';
531 $languages['ro']['ALIAS'] = 'ro_RO';
533 $languages['ru_RU']['NAME'] = 'Russian';
534 $languages['ru_RU']['ALTNAME'] = 'Русский';
535 $languages['ru_RU']['CHARSET'] = 'utf-8';
536 $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8';
537 $languages['ru']['ALIAS'] = 'ru_RU';
539 $languages['sk_SK']['NAME'] = 'Slovak';
540 $languages['sk_SK']['CHARSET'] = 'iso-8859-2';
541 $languages['sk_SK']['LOCALE'] = 'sk_SK.ISO8859-2';
542 $languages['sk']['ALIAS'] = 'sk_SK';
544 $languages['sl_SI']['NAME'] = 'Slovenian';
545 $languages['sl_SI']['ALTNAME'] = 'Slovenščina';
546 $languages['sl_SI']['CHARSET'] = 'iso-8859-2';
547 $languages['sl_SI']['LOCALE'] = 'sl_SI.ISO8859-2';
548 $languages['sl']['ALIAS'] = 'sl_SI';
550 $languages['sr_YU']['NAME'] = 'Serbian';
551 $languages['sr_YU']['ALTNAME'] = 'Srpski';
552 $languages['sr_YU']['CHARSET'] = 'iso-8859-2';
553 $languages['sr_YU']['LOCALE'] = 'sr_YU.ISO8859-2';
554 $languages['sr']['ALIAS'] = 'sr_YU';
556 $languages['sv_SE']['NAME'] = 'Swedish';
557 $languages['sv_SE']['ALTNAME'] = 'Svenska';
558 $languages['sv_SE']['CHARSET'] = 'iso-8859-1';
559 $languages['sv_SE']['LOCALE'] = 'sv_SE.ISO8859-1';
560 $languages['sv']['ALIAS'] = 'sv_SE';
562 $languages['th_TH']['NAME'] = 'Thai';
563 $languages['th_TH']['CHARSET'] = 'tis-620';
564 $languages['th_TH']['LOCALE'] = 'th_TH.TIS-620';
565 $languages['th']['ALIAS'] = 'th_TH';
567 $languages['tl_PH']['NAME'] = 'Tagalog';
568 $languages['tl_PH']['CHARSET'] = 'iso-8859-1';
569 $languages['tl_PH']['LOCALE'] = 'tl_PH.ISO8859-1';
570 $languages['tl']['ALIAS'] = 'tl_PH';
572 $languages['tr_TR']['NAME'] = 'Turkish';
573 $languages['tr_TR']['CHARSET'] = 'iso-8859-9';
574 $languages['tr_TR']['LOCALE'] = 'tr_TR.ISO8859-9';
575 $languages['tr']['ALIAS'] = 'tr_TR';
577 $languages['zh_TW']['NAME'] = 'Chinese Trad';
578 $languages['zh_TW']['CHARSET'] = 'big5';
579 $languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5';
580 $languages['tw']['ALIAS'] = 'zh_TW';
582 $languages['zh_CN']['NAME'] = 'Chinese Simp';
583 $languages['zh_CN']['CHARSET'] = 'gb2312';
584 $languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312';
585 $languages['cn']['ALIAS'] = 'zh_CN';
587 $languages['uk_UA']['NAME'] = 'Ukrainian';
588 $languages['uk_UA']['CHARSET'] = 'koi8-u';
589 $languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U';
590 $languages['uk']['ALIAS'] = 'uk_UA';
592 $languages['ru_UA']['NAME'] = 'Russian (Ukrainian)';
593 $languages['ru_UA']['CHARSET'] = 'koi8-r';
594 $languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R';
597 $languages['vi_VN']['NAME'] = 'Vietnamese';
598 $languages['vi_VN']['CHARSET'] = 'utf-8';
599 $languages['vi']['ALIAS'] = 'vi_VN';
602 // Right to left languages
603 $languages['ar']['NAME'] = 'Arabic';
604 $languages['ar']['CHARSET'] = 'windows-1256';
605 $languages['ar']['DIR'] = 'rtl';
607 $languages['fa_IR']['NAME'] = 'Farsi';
608 $languages['fa_IR']['CHARSET'] = 'utf-8';
609 $languages['fa_IR']['DIR'] = 'rtl';
610 $languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8';
611 $languages['fa']['ALIAS'] = 'fa_IR';
613 $languages['he_IL']['NAME'] = 'Hebrew';
614 $languages['he_IL']['CHARSET'] = 'windows-1255';
615 $languages['he_IL']['LOCALE'] = 'he_IL.CP1255';
616 $languages['he_IL']['DIR'] = 'rtl';
617 $languages['he']['ALIAS'] = 'he_IL';
619 /* Detect whether gettext is installed. */
621 if (function_exists('_')) {
624 if (function_exists('bindtextdomain')) {
627 if (function_exists('textdomain')) {
631 /* If gettext is fully loaded, cool */
632 if ($gettext_flags == 7) {
635 /* If we can fake gettext, try that */
636 elseif ($gettext_flags == 0) {
638 include_once(SM_PATH
. 'functions/gettext.php');
640 /* Uh-ho. A weird install */
641 if (! $gettext_flags & 1) {
643 * Function is used as replacement in broken installs
650 if (! $gettext_flags & 2) {
652 * Function is used as replacement in broken installs
655 function bindtextdomain() {
659 if (! $gettext_flags & 4) {
661 * Function is used as replacemet in broken installs
664 function textdomain() {
672 * Japanese charset extra function
674 * Action performed by function is defined by first argument.
675 * Default return value is defined by second argument.
676 * Use of third argument depends on action.
678 * @param string $action action performed by this function.
680 * decode - convert returned string to euc-jp. third argument unused
681 * encode - convert returned string to jis. third argument unused
682 * strimwidth - third argument=$width. trims string to $width symbols.
683 * encodeheader - create base64 encoded header in iso-2022-jp. third argument unused
684 * decodeheader - return human readable string from mime header. string is returned in euc-jp. third argument unused
685 * downloadfilename - third argument $useragent. Arguments provide browser info. Returns shift-jis or euc-jp encoded file name
686 * wordwrap - third argument=$wrap. wraps text at $wrap symbols
687 * utf7-imap_encode - returns string converted from euc-jp to utf7-imap. third argument unused
688 * utf7-imap_decode - returns string converted from utf7-imap to euc-jp. third argument unused
689 * @param string $ret default return value
691 function japanese_charset_xtra() {
692 $ret = func_get_arg(1); /* default return value */
693 if (function_exists('mb_detect_encoding')) {
694 switch (func_get_arg(0)) { /* action */
696 $detect_encoding = @mb_detect_encoding
($ret);
697 if ($detect_encoding == 'JIS' ||
698 $detect_encoding == 'EUC-JP' ||
699 $detect_encoding == 'SJIS' ||
700 $detect_encoding == 'UTF-8') {
702 $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV");
706 $detect_encoding = @mb_detect_encoding
($ret);
707 if ($detect_encoding == 'JIS' ||
708 $detect_encoding == 'EUC-JP' ||
709 $detect_encoding == 'SJIS' ||
710 $detect_encoding == 'UTF-8') {
712 $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO');
716 $width = func_get_arg(2);
717 $ret = mb_strimwidth($ret, 0, $width, '...');
721 if (strlen($ret) > 0) {
722 $tmpstr = mb_substr($ret, 0, 1);
723 $prevcsize = strlen($tmpstr);
724 for ($i = 1; $i < mb_strlen($ret); $i++
) {
725 $tmp = mb_substr($ret, $i, 1);
726 if (strlen($tmp) == $prevcsize) {
729 if ($prevcsize == 1) {
732 $result .= str_replace(' ', '',
733 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
736 $prevcsize = strlen($tmp);
739 if (strlen($tmpstr)) {
740 if (strlen(mb_substr($tmpstr, 0, 1)) == 1)
743 $result .= str_replace(' ', '',
744 mb_encode_mimeheader($tmpstr,'iso-2022-jp','B',''));
750 $ret = str_replace("\t", "", $ret);
751 if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret))
752 $ret = @mb_decode_mimeheader
($ret);
753 $ret = @mb_convert_encoding
($ret, 'EUC-JP', 'AUTO');
755 case 'downloadfilename':
756 $useragent = func_get_arg(2);
757 if (strstr($useragent, 'Windows') !== false ||
758 strstr($useragent, 'Mac_') !== false) {
759 $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO');
761 $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO');
765 $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" .
766 "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" .
767 "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" .
768 "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" .
769 "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" .
770 "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" .
771 "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" .
772 "\xa8\xa1\xa9\xa1\xcf\xa1\xd1";
773 $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" .
774 "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef";
775 $wrap = func_get_arg(2);
777 if (strlen($ret) >= $wrap &&
778 substr($ret, 0, 1) != '>' &&
779 strpos($ret, 'http://') === FALSE &&
780 strpos($ret, 'https://') === FALSE &&
781 strpos($ret, 'ftp://') === FALSE) {
783 $ret = mb_convert_kana($ret, "KV");
788 while ($ptr < strlen($ret) - 1) {
789 $l = mb_strcut($ret, $ptr, $wrap);
793 $l = mb_strcut($ret, $ptr, 2);
794 while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) {
797 $l = mb_strcut($ret, $ptr, 1);
800 if ($ptr < strlen($ret) - 1)
806 case 'utf7-imap_encode':
807 $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP');
809 case 'utf7-imap_decode':
810 $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP');
819 * Korean charset extra functions
821 * Action performed by function is defined by first argument.
822 * Default return value is defined by second argument.
824 * @param string action performed by this function.
826 * downloadfilename - Hangul(Korean Character) Attached File Name Fix.
827 * @param string default return value
829 function korean_charset_xtra() {
831 $ret = func_get_arg(1); /* default return value */
832 if (func_get_arg(0) == 'downloadfilename') { /* action */
833 $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */
834 for ($i=0;$i<strlen($ret);$i++
) {
835 if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */
838 } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') ||
/* From Original ereg_replace in download.php */
839 ($ret[$i] >= 'A' && $ret[$i] <= 'Z') ||
840 ($ret[$i] == '.') ||
($ret[$i] == '-')) {
852 * Replaces non-braking spaces inserted by some browsers with regular space
854 * This function can be used to replace non-braking space symbols
855 * that are inserted in forms by some browsers instead of normal
858 * @param string $string Text that needs to be cleaned
859 * @param string $charset Charset used in text
860 * @return string Cleaned text
862 function cleanup_nbsp($string,$charset) {
864 // reduce number of case statements
865 if (stristr('iso-8859-',substr($charset,0,9))){
866 $output_charset="iso-8859-x";
868 if (stristr('windows-125',substr($charset,0,11))){
869 $output_charset="cp125x";
871 if (stristr('koi8',substr($charset,0,4))){
872 $output_charset="koi8-x";
874 if (! isset($output_charset)){
875 $output_charset=strtolower($charset);
878 // where is non-braking space symbol
879 switch($output_charset):
892 // don't change string if charset is unmatched
896 // return space instead of non-braking space.
897 return str_replace($nbsp,' ',$string);
901 * Function informs if it is safe to convert given charset to the one that is used by user.
903 * It is safe to use conversion only if user uses utf-8 encoding and when
904 * converted charset is similar to the one that is used by user.
906 * @param string $input_charset Charset of text that needs to be converted
907 * @return bool is it possible to convert to user's charset
909 function is_conversion_safe($input_charset) {
910 global $languages, $sm_notAlias, $default_charset;
912 // convert to lower case
913 $input_charset = strtolower($input_charset);
915 // Is user's locale Unicode based ?
916 if ( $default_charset == "utf-8" ) {
920 // Charsets that are similar
921 switch ($default_charset):
923 if ( $input_charset == "iso-8859-5" ||
924 $input_charset == "koi8-r" ||
925 $input_charset == "koi8-u" ) {
931 if ( $input_charset == "iso-8859-13" ||
932 $input_charset == "iso-8859-4" ) {
938 if ( $input_charset == "iso-8859-13" ||
939 $input_charset == "windows-1257" ) {
945 if ( $input_charset == "windows-1251" ||
946 $input_charset == "koi8-r" ||
947 $input_charset == "koi8-u" ) {
953 if ( $input_charset == "iso-8859-4" ||
954 $input_charset == "windows-1257" ) {
960 if ( $input_charset == "windows-1251" ||
961 $input_charset == "iso-8859-5" ||
962 $input_charset == "koi8-u" ) {
968 if ( $input_charset == "windows-1251" ||
969 $input_charset == "iso-8859-5" ||
970 $input_charset == "koi8-r" ) {