| 1 | <?php |
| 2 | /** |
| 3 | * SquirrelMail internationalization functions |
| 4 | * |
| 5 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
| 6 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 7 | * |
| 8 | * This file contains variuos functions that are needed to do |
| 9 | * internationalization of SquirrelMail. |
| 10 | * |
| 11 | * Internally the output character set is used. Other characters are |
| 12 | * encoded using Unicode entities according to HTML 4.0. |
| 13 | * |
| 14 | * @version $Id$ |
| 15 | * @package squirrelmail |
| 16 | * @subpackage i18n |
| 17 | */ |
| 18 | |
| 19 | /** Everything uses global.php... */ |
| 20 | require_once(SM_PATH . 'functions/global.php'); |
| 21 | |
| 22 | /** |
| 23 | * Gettext bindtextdomain wrapper. |
| 24 | * |
| 25 | * Wrapper solves differences between php versions in order to provide |
| 26 | * ngettext support. Should be used if translation uses ngettext |
| 27 | * functions. |
| 28 | * @since 1.5.1 |
| 29 | * @param string $domain gettext domain name |
| 30 | * @param string $dir directory that contains all translations |
| 31 | * @return string path to translation directory |
| 32 | */ |
| 33 | function sq_bindtextdomain($domain,$dir) { |
| 34 | global $l10n, $gettext_flags, $sm_notAlias; |
| 35 | |
| 36 | if ($gettext_flags==7) { |
| 37 | // gettext extension without ngettext |
| 38 | if (substr($dir, -1) != '/') $dir .= '/'; |
| 39 | $mofile=$dir . $sm_notAlias . '/LC_MESSAGES/' . $domain . '.mo'; |
| 40 | $input = new FileReader($mofile); |
| 41 | $l10n[$domain] = new gettext_reader($input); |
| 42 | } |
| 43 | |
| 44 | $dir=bindtextdomain($domain,$dir); |
| 45 | |
| 46 | return $dir; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Gettext textdomain wrapper. |
| 51 | * Makes sure that gettext_domain global is modified. |
| 52 | * @since 1.5.1 |
| 53 | * @param string $name gettext domain name |
| 54 | * @return string gettext domain name |
| 55 | */ |
| 56 | function sq_textdomain($domain) { |
| 57 | global $gettext_domain; |
| 58 | $gettext_domain=textdomain($domain); |
| 59 | return $gettext_domain; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * php setlocale function wrapper |
| 64 | * |
| 65 | * From php 4.3.0 it is possible to use arrays in order to set locale. |
| 66 | * php gettext extension works only when locale is set. This wrapper |
| 67 | * function allows to use more than one locale name. |
| 68 | * |
| 69 | * @param int $category locale category name. Use php named constants |
| 70 | * (LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME) |
| 71 | * @param mixed $locale option contains array with possible locales or string with one locale |
| 72 | * @return string name of set locale or false, if all locales fail. |
| 73 | * @since 1.5.1 |
| 74 | * @see http://www.php.net/setlocale |
| 75 | */ |
| 76 | function sq_setlocale($category,$locale) { |
| 77 | // string with only one locale |
| 78 | if (is_string($locale)) |
| 79 | return setlocale($category,$locale); |
| 80 | |
| 81 | if (! check_php_version(4,3)) { |
| 82 | $ret=false; |
| 83 | $index=0; |
| 84 | while ( ! $ret && $index<count($locale)) { |
| 85 | $ret=setlocale($category,$locale[$index]); |
| 86 | $index++; |
| 87 | } |
| 88 | } else { |
| 89 | // php 4.3.0 or better, use entire array |
| 90 | $ret=setlocale($category,$locale); |
| 91 | } |
| 92 | return $ret; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Converts string from given charset to charset, that can be displayed by user translation. |
| 97 | * |
| 98 | * Function by default returns html encoded strings, if translation uses different encoding. |
| 99 | * If Japanese translation is used - function returns string converted to euc-jp |
| 100 | * If iconv or recode functions are enabled and translation uses utf-8 - function returns utf-8 encoded string. |
| 101 | * If $charset is not supported - function returns unconverted string. |
| 102 | * |
| 103 | * sanitizing of html tags is also done by this function. |
| 104 | * |
| 105 | * @param string $charset |
| 106 | * @param string $string Text to be decoded |
| 107 | * @return string decoded string |
| 108 | */ |
| 109 | function charset_decode ($charset, $string) { |
| 110 | global $languages, $squirrelmail_language, $default_charset; |
| 111 | global $use_php_recode, $use_php_iconv, $aggressive_decoding; |
| 112 | |
| 113 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
| 114 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { |
| 115 | $string = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $string); |
| 116 | } |
| 117 | |
| 118 | $charset = strtolower($charset); |
| 119 | |
| 120 | set_my_charset(); |
| 121 | |
| 122 | // Variables that allow to use functions without function_exist() calls |
| 123 | if (! isset($use_php_recode) || $use_php_recode=="" ) { |
| 124 | $use_php_recode=false; } |
| 125 | if (! isset($use_php_iconv) || $use_php_iconv=="" ) { |
| 126 | $use_php_iconv=false; } |
| 127 | |
| 128 | // Don't do conversion if charset is the same. |
| 129 | if ( $charset == strtolower($default_charset) ) |
| 130 | return htmlspecialchars($string); |
| 131 | |
| 132 | // catch iso-8859-8-i thing |
| 133 | if ( $charset == "iso-8859-8-i" ) |
| 134 | $charset = "iso-8859-8"; |
| 135 | |
| 136 | /* |
| 137 | * Recode converts html special characters automatically if you use |
| 138 | * 'charset..html' decoding. There is no documented way to put -d option |
| 139 | * into php recode function call. |
| 140 | */ |
| 141 | if ( $use_php_recode ) { |
| 142 | if ( $default_charset == "utf-8" ) { |
| 143 | // other charsets can be converted to utf-8 without loss. |
| 144 | // and output string is smaller |
| 145 | $string = recode_string($charset . "..utf-8",$string); |
| 146 | return htmlspecialchars($string); |
| 147 | } else { |
| 148 | $string = recode_string($charset . "..html",$string); |
| 149 | // recode does not convert single quote, htmlspecialchars does. |
| 150 | $string = str_replace("'", ''', $string); |
| 151 | return $string; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // iconv functions does not have html target and can be used only with utf-8 |
| 156 | if ( $use_php_iconv && $default_charset=='utf-8') { |
| 157 | $string = iconv($charset,$default_charset,$string); |
| 158 | return htmlspecialchars($string); |
| 159 | } |
| 160 | |
| 161 | // If we don't use recode and iconv, we'll do it old way. |
| 162 | |
| 163 | /* All HTML special characters are 7 bit and can be replaced first */ |
| 164 | |
| 165 | $string = htmlspecialchars ($string); |
| 166 | |
| 167 | /* controls cpu and memory intensive decoding cycles */ |
| 168 | if (! isset($aggressive_decoding) || $aggressive_decoding=="" ) { |
| 169 | $aggressive_decoding=false; } |
| 170 | |
| 171 | $decode=fixcharset($charset); |
| 172 | $decodefile=SM_PATH . 'functions/decode/' . $decode . '.php'; |
| 173 | if (file_exists($decodefile)) { |
| 174 | include_once($decodefile); |
| 175 | $ret = call_user_func('charset_decode_'.$decode, $string); |
| 176 | } else { |
| 177 | $ret = $string; |
| 178 | } |
| 179 | return( $ret ); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Converts html string to given charset |
| 184 | * @since 1.5.1 |
| 185 | * @param string $string |
| 186 | * @param string $charset |
| 187 | * @param boolean $htmlencode keep htmlspecialchars encoding |
| 188 | * @param string |
| 189 | */ |
| 190 | function charset_encode($string,$charset,$htmlencode=true) { |
| 191 | global $default_charset; |
| 192 | |
| 193 | $encode=fixcharset($charset); |
| 194 | $encodefile=SM_PATH . 'functions/encode/' . $encode . '.php'; |
| 195 | if (file_exists($encodefile)) { |
| 196 | include_once($encodefile); |
| 197 | $ret = call_user_func('charset_encode_'.$encode, $string); |
| 198 | } else { |
| 199 | include_once(SM_PATH . 'functions/encode/us_ascii.php'); |
| 200 | $ret = charset_encode_us_ascii($string); |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Undo html special chars, some places (like compose form) have |
| 205 | * own sanitizing functions and don't need html symbols. |
| 206 | * Undo chars only after encoding in order to prevent conversion of |
| 207 | * html entities in plain text emails. |
| 208 | */ |
| 209 | if (! $htmlencode ) { |
| 210 | $ret = str_replace(array('&','>','<','"'),array('&','>','<','"'),$ret); |
| 211 | } |
| 212 | return( $ret ); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Combined decoding and encoding functions |
| 217 | * |
| 218 | * If conversion is done to charset different that utf-8, unsupported symbols |
| 219 | * will be replaced with question marks. |
| 220 | * @since 1.5.1 |
| 221 | * @param string $in_charset initial charset |
| 222 | * @param string $string string that has to be converted |
| 223 | * @param string $out_charset final charset |
| 224 | * @param boolean $htmlencode keep htmlspecialchars encoding |
| 225 | * @return string converted string |
| 226 | */ |
| 227 | function charset_convert($in_charset,$string,$out_charset,$htmlencode=true) { |
| 228 | $string=charset_decode($in_charset,$string); |
| 229 | $string=charset_encode($string,$out_charset,$htmlencode); |
| 230 | return $string; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Makes charset name suitable for decoding cycles |
| 235 | * |
| 236 | * @since 1.5.0 |
| 237 | * @param string $charset Name of charset |
| 238 | * @return string $charset Adjusted name of charset |
| 239 | */ |
| 240 | function fixcharset($charset) { |
| 241 | /* remove minus and characters that might be used in paths from charset |
| 242 | * name in order to be able to use it in function names and include calls. |
| 243 | */ |
| 244 | $charset=preg_replace("/[-:.\/\\\]/",'_',$charset); |
| 245 | |
| 246 | // windows-125x and cp125x charsets |
| 247 | $charset=str_replace('windows_','cp',$charset); |
| 248 | |
| 249 | // ibm > cp |
| 250 | $charset=str_replace('ibm','cp',$charset); |
| 251 | |
| 252 | // iso-8859-8-i -> iso-8859-8 |
| 253 | // use same cycle until I'll find differences |
| 254 | $charset=str_replace('iso_8859_8_i','iso_8859_8',$charset); |
| 255 | |
| 256 | return $charset; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Set up the language to be output |
| 261 | * if $do_search is true, then scan the browser information |
| 262 | * for a possible language that we know |
| 263 | * |
| 264 | * Function sets system locale environment (LC_ALL, LANG, LANGUAGE), |
| 265 | * gettext translation bindings and html header information. |
| 266 | * |
| 267 | * Function returns error codes, if there is some fatal error. |
| 268 | * 0 = no error, |
| 269 | * 1 = mbstring support is not present, |
| 270 | * 2 = mbstring support is not present, user's translation reverted to en_US. |
| 271 | * |
| 272 | * @param string $sm_language translation used by user's interface |
| 273 | * @param bool $do_search use browser's preferred language detection functions. Defaults to false. |
| 274 | * @param bool $default set $sm_language to $squirrelmail_default_language if language detection fails or language is not set. Defaults to false. |
| 275 | * @return int function execution error codes. |
| 276 | */ |
| 277 | function set_up_language($sm_language, $do_search = false, $default = false) { |
| 278 | |
| 279 | static $SetupAlready = 0; |
| 280 | global $use_gettext, $languages, |
| 281 | $squirrelmail_language, $squirrelmail_default_language, $default_charset, |
| 282 | $sm_notAlias, $username, $data_dir; |
| 283 | |
| 284 | if ($SetupAlready) { |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | $SetupAlready = TRUE; |
| 289 | sqgetGlobalVar('HTTP_ACCEPT_LANGUAGE', $accept_lang, SQ_SERVER); |
| 290 | |
| 291 | if ($do_search && ! $sm_language && isset($accept_lang)) { |
| 292 | $sm_language = substr($accept_lang, 0, 2); |
| 293 | } |
| 294 | |
| 295 | if ((!$sm_language||$default) && isset($squirrelmail_default_language)) { |
| 296 | $squirrelmail_language = $squirrelmail_default_language; |
| 297 | $sm_language = $squirrelmail_default_language; |
| 298 | } |
| 299 | $sm_notAlias = $sm_language; |
| 300 | |
| 301 | // Catching removed translation |
| 302 | // System reverts to English translation if user prefs contain translation |
| 303 | // that is not available in $languages array |
| 304 | if (!isset($languages[$sm_notAlias])) { |
| 305 | $sm_notAlias="en_US"; |
| 306 | } |
| 307 | |
| 308 | while (isset($languages[$sm_notAlias]['ALIAS'])) { |
| 309 | $sm_notAlias = $languages[$sm_notAlias]['ALIAS']; |
| 310 | } |
| 311 | |
| 312 | if ( isset($sm_language) && |
| 313 | $use_gettext && |
| 314 | $sm_language != '' && |
| 315 | isset($languages[$sm_notAlias]['CHARSET']) ) { |
| 316 | sq_bindtextdomain( 'squirrelmail', SM_PATH . 'locale/' ); |
| 317 | sq_textdomain( 'squirrelmail' ); |
| 318 | |
| 319 | // set codeset in order to avoid gettext charset conversions |
| 320 | if (function_exists('bind_textdomain_codeset')) { |
| 321 | // Japanese translation uses different internal charset |
| 322 | if ($sm_notAlias == 'ja_JP') { |
| 323 | bind_textdomain_codeset ("squirrelmail", 'EUC-JP'); |
| 324 | } else { |
| 325 | bind_textdomain_codeset ("squirrelmail", $languages[$sm_notAlias]['CHARSET'] ); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | // Use LOCALE key, if it is set. |
| 330 | if (isset($languages[$sm_notAlias]['LOCALE'])){ |
| 331 | $longlocale=$languages[$sm_notAlias]['LOCALE']; |
| 332 | } else { |
| 333 | $longlocale=$sm_notAlias; |
| 334 | } |
| 335 | |
| 336 | // try setting locale |
| 337 | $retlocale=sq_setlocale(LC_ALL, $longlocale); |
| 338 | |
| 339 | // check if locale is set and assign that locale to $longlocale |
| 340 | // in order to use it in putenv calls. |
| 341 | if (! is_bool($retlocale)) { |
| 342 | $longlocale=$retlocale; |
| 343 | } elseif (is_array($longlocale)) { |
| 344 | // setting of all locales failed. |
| 345 | // we need string instead of array used in LOCALE key. |
| 346 | $longlocale=$sm_notAlias; |
| 347 | } |
| 348 | |
| 349 | if ( !((bool)ini_get('safe_mode')) && |
| 350 | getenv( 'LC_ALL' ) != $longlocale ) { |
| 351 | putenv( "LC_ALL=$longlocale" ); |
| 352 | putenv( "LANG=$longlocale" ); |
| 353 | putenv( "LANGUAGE=$longlocale" ); |
| 354 | putenv( "LC_NUMERIC=C" ); |
| 355 | if ($sm_notAlias=='tr_TR') putenv( "LC_CTYPE=C" ); |
| 356 | } |
| 357 | // Workaround for plugins that use numbers with floating point |
| 358 | // It might be removed if plugins use correct decimal delimiters |
| 359 | // according to locale settings. |
| 360 | setlocale(LC_NUMERIC, 'C'); |
| 361 | // Workaround for specific Turkish strtolower/strtoupper rules. |
| 362 | // Many functions expect English conversion rules. |
| 363 | if ($sm_notAlias=='tr_TR') setlocale(LC_CTYPE,'C'); |
| 364 | |
| 365 | // Set text direction/alignment variables |
| 366 | // These don't appear to be used... are they safe to remove? |
| 367 | if (isset($languages[$sm_notAlias]['DIR']) && |
| 368 | $languages[$sm_notAlias]['DIR'] == 'rtl') { |
| 369 | /** |
| 370 | * Text direction |
| 371 | * @global string $text_direction |
| 372 | */ |
| 373 | $text_direction='rtl'; |
| 374 | /** |
| 375 | * Left alignment |
| 376 | * @global string $left_align |
| 377 | */ |
| 378 | $left_align='right'; |
| 379 | /** |
| 380 | * Right alignment |
| 381 | * @global string $right_align |
| 382 | */ |
| 383 | $right_align='left'; |
| 384 | } else { |
| 385 | $text_direction='ltr'; |
| 386 | $left_align='left'; |
| 387 | $right_align='right'; |
| 388 | } |
| 389 | |
| 390 | $squirrelmail_language = $sm_notAlias; |
| 391 | if ($squirrelmail_language == 'ja_JP') { |
| 392 | header ('Content-Type: text/html; charset=EUC-JP'); |
| 393 | if (!function_exists('mb_internal_encoding')) { |
| 394 | // Error messages can't be displayed here |
| 395 | $error = 1; |
| 396 | // Revert to English if possible. |
| 397 | if (function_exists('setPref') && $username!='' && $data_dir!="") { |
| 398 | setPref($data_dir, $username, 'language', "en_US"); |
| 399 | $error = 2; |
| 400 | } |
| 401 | // stop further execution in order not to get php errors on mb_internal_encoding(). |
| 402 | return $error; |
| 403 | } |
| 404 | if (function_exists('mb_language')) { |
| 405 | mb_language('Japanese'); |
| 406 | } |
| 407 | mb_internal_encoding('EUC-JP'); |
| 408 | mb_http_output('pass'); |
| 409 | } elseif ($squirrelmail_language == 'en_US') { |
| 410 | header( 'Content-Type: text/html; charset=' . $default_charset ); |
| 411 | } else { |
| 412 | header( 'Content-Type: text/html; charset=' . $languages[$sm_notAlias]['CHARSET'] ); |
| 413 | } |
| 414 | } |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * Sets default_charset variable according to the one that is used by user's translations. |
| 420 | * |
| 421 | * Function changes global $default_charset variable in order to be sure, that it |
| 422 | * contains charset used by user's translation. Sanity of $squirrelmail_default_language |
| 423 | * and $default_charset combination provided in SquirrelMail config is also tested. |
| 424 | * |
| 425 | * There can be a $default_charset setting in the |
| 426 | * config.php file, but the user may have a different language |
| 427 | * selected for a user interface. This function checks the |
| 428 | * language selected by the user and tags the outgoing messages |
| 429 | * with the appropriate charset corresponding to the language |
| 430 | * selection. This is "more right" (tm), than just stamping the |
| 431 | * message blindly with the system-wide $default_charset. |
| 432 | */ |
| 433 | function set_my_charset(){ |
| 434 | global $data_dir, $username, $default_charset, $languages, $squirrelmail_default_language; |
| 435 | |
| 436 | $my_language = getPref($data_dir, $username, 'language'); |
| 437 | if (!$my_language) { |
| 438 | $my_language = $squirrelmail_default_language ; |
| 439 | } |
| 440 | // Catch removed translation |
| 441 | if (!isset($languages[$my_language])) { |
| 442 | $my_language="en_US"; |
| 443 | } |
| 444 | while (isset($languages[$my_language]['ALIAS'])) { |
| 445 | $my_language = $languages[$my_language]['ALIAS']; |
| 446 | } |
| 447 | $my_charset = $languages[$my_language]['CHARSET']; |
| 448 | if ($my_language!='en_US') { |
| 449 | $default_charset = $my_charset; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /************************** |
| 454 | * Japanese extra functions |
| 455 | **************************/ |
| 456 | |
| 457 | /** |
| 458 | * Japanese decoding function |
| 459 | * |
| 460 | * converts string to euc-jp, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
| 461 | * charset. Needs mbstring support in php. |
| 462 | * @param string $ret text, that has to be converted |
| 463 | * @return string converted string |
| 464 | * @since 1.5.1 |
| 465 | */ |
| 466 | function japanese_xtra_decode($ret) { |
| 467 | if (function_exists('mb_detect_encoding')) { |
| 468 | $detect_encoding = @mb_detect_encoding($ret); |
| 469 | if ($detect_encoding == 'JIS' || |
| 470 | $detect_encoding == 'EUC-JP' || |
| 471 | $detect_encoding == 'SJIS' || |
| 472 | $detect_encoding == 'UTF-8') { |
| 473 | |
| 474 | $ret = mb_convert_kana(mb_convert_encoding($ret, 'EUC-JP', 'AUTO'), "KV"); |
| 475 | } |
| 476 | } |
| 477 | return $ret; |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * Japanese encoding function |
| 482 | * |
| 483 | * converts string to jis, if string uses JIS, EUC-JP, ShiftJIS or UTF-8 |
| 484 | * charset. Needs mbstring support in php. |
| 485 | * @param string $ret text, that has to be converted |
| 486 | * @return string converted text |
| 487 | * @since 1.5.1 |
| 488 | */ |
| 489 | function japanese_xtra_encode($ret) { |
| 490 | if (function_exists('mb_detect_encoding')) { |
| 491 | $detect_encoding = @mb_detect_encoding($ret); |
| 492 | if ($detect_encoding == 'JIS' || |
| 493 | $detect_encoding == 'EUC-JP' || |
| 494 | $detect_encoding == 'SJIS' || |
| 495 | $detect_encoding == 'UTF-8') { |
| 496 | |
| 497 | $ret = mb_convert_encoding(mb_convert_kana($ret, "KV"), 'JIS', 'AUTO'); |
| 498 | } |
| 499 | } |
| 500 | return $ret; |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * Japanese header encoding function |
| 505 | * |
| 506 | * creates base64 encoded header in iso-2022-jp charset |
| 507 | * @param string $ret text, that has to be converted |
| 508 | * @return string mime base64 encoded string |
| 509 | * @since 1.5.1 |
| 510 | */ |
| 511 | function japanese_xtra_encodeheader($ret) { |
| 512 | if (function_exists('mb_detect_encoding')) { |
| 513 | $result = ''; |
| 514 | if (strlen($ret) > 0) { |
| 515 | $tmpstr = mb_substr($ret, 0, 1); |
| 516 | $prevcsize = strlen($tmpstr); |
| 517 | for ($i = 1; $i < mb_strlen($ret); $i++) { |
| 518 | $tmp = mb_substr($ret, $i, 1); |
| 519 | if (strlen($tmp) == $prevcsize) { |
| 520 | $tmpstr .= $tmp; |
| 521 | } else { |
| 522 | if ($prevcsize == 1) { |
| 523 | $result .= $tmpstr; |
| 524 | } else { |
| 525 | $result .= str_replace(' ', '', |
| 526 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 527 | } |
| 528 | $tmpstr = $tmp; |
| 529 | $prevcsize = strlen($tmp); |
| 530 | } |
| 531 | } |
| 532 | if (strlen($tmpstr)) { |
| 533 | if (strlen(mb_substr($tmpstr, 0, 1)) == 1) |
| 534 | $result .= $tmpstr; |
| 535 | else |
| 536 | $result .= str_replace(' ', '', |
| 537 | mb_encode_mimeheader($tmpstr,'iso-2022-jp','B','')); |
| 538 | } |
| 539 | } |
| 540 | $ret = $result; |
| 541 | } |
| 542 | return $ret; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * Japanese header decoding function |
| 547 | * |
| 548 | * return human readable string from mime header. string is returned in euc-jp |
| 549 | * charset. |
| 550 | * @param string $ret header string |
| 551 | * @return string decoded header string |
| 552 | * @since 1.5.1 |
| 553 | */ |
| 554 | function japanese_xtra_decodeheader($ret) { |
| 555 | if (function_exists('mb_detect_encoding')) { |
| 556 | $ret = str_replace("\t", "", $ret); |
| 557 | if (eregi('=\\?([^?]+)\\?(q|b)\\?([^?]+)\\?=', $ret)) |
| 558 | $ret = @mb_decode_mimeheader($ret); |
| 559 | $ret = @mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 560 | } |
| 561 | return $ret; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * Japanese downloaded filename processing function |
| 566 | * |
| 567 | * Returns shift-jis or euc-jp encoded file name |
| 568 | * @param string $ret string |
| 569 | * @param string $useragent browser |
| 570 | * @return string converted string |
| 571 | * @since 1.5.1 |
| 572 | */ |
| 573 | function japanese_xtra_downloadfilename($ret,$useragent) { |
| 574 | if (function_exists('mb_detect_encoding')) { |
| 575 | if (strstr($useragent, 'Windows') !== false || |
| 576 | strstr($useragent, 'Mac_') !== false) { |
| 577 | $ret = mb_convert_encoding($ret, 'SJIS', 'AUTO'); |
| 578 | } else { |
| 579 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'AUTO'); |
| 580 | } |
| 581 | } |
| 582 | return $ret; |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * Japanese wordwrap function |
| 587 | * |
| 588 | * wraps text at set number of symbols |
| 589 | * @param string $ret text |
| 590 | * @param integer $wrap number of symbols per line |
| 591 | * @return string wrapped text |
| 592 | * @since 1.5.1 |
| 593 | */ |
| 594 | function japanese_xtra_wordwrap($ret,$wrap) { |
| 595 | if (function_exists('mb_detect_encoding')) { |
| 596 | $no_begin = "\x21\x25\x29\x2c\x2e\x3a\x3b\x3f\x5d\x7d\xa1\xf1\xa1\xeb\xa1" . |
| 597 | "\xc7\xa1\xc9\xa2\xf3\xa1\xec\xa1\xed\xa1\xee\xa1\xa2\xa1\xa3\xa1\xb9" . |
| 598 | "\xa1\xd3\xa1\xd5\xa1\xd7\xa1\xd9\xa1\xdb\xa1\xcd\xa4\xa1\xa4\xa3\xa4" . |
| 599 | "\xa5\xa4\xa7\xa4\xa9\xa4\xc3\xa4\xe3\xa4\xe5\xa4\xe7\xa4\xee\xa1\xab" . |
| 600 | "\xa1\xac\xa1\xb5\xa1\xb6\xa5\xa1\xa5\xa3\xa5\xa5\xa5\xa7\xa5\xa9\xa5" . |
| 601 | "\xc3\xa5\xe3\xa5\xe5\xa5\xe7\xa5\xee\xa5\xf5\xa5\xf6\xa1\xa6\xa1\xbc" . |
| 602 | "\xa1\xb3\xa1\xb4\xa1\xaa\xa1\xf3\xa1\xcb\xa1\xa4\xa1\xa5\xa1\xa7\xa1" . |
| 603 | "\xa8\xa1\xa9\xa1\xcf\xa1\xd1"; |
| 604 | // This don't appear to be used... is it safe to remove? |
| 605 | $no_end = "\x5c\x24\x28\x5b\x7b\xa1\xf2\x5c\xa1\xc6\xa1\xc8\xa1\xd2\xa1" . |
| 606 | "\xd4\xa1\xd6\xa1\xd8\xa1\xda\xa1\xcc\xa1\xf0\xa1\xca\xa1\xce\xa1\xd0\xa1\xef"; |
| 607 | |
| 608 | if (strlen($ret) >= $wrap && |
| 609 | substr($ret, 0, 1) != '>' && |
| 610 | strpos($ret, 'http://') === FALSE && |
| 611 | strpos($ret, 'https://') === FALSE && |
| 612 | strpos($ret, 'ftp://') === FALSE) { |
| 613 | |
| 614 | $ret = mb_convert_kana($ret, "KV"); |
| 615 | |
| 616 | $line_new = ''; |
| 617 | $ptr = 0; |
| 618 | |
| 619 | while ($ptr < strlen($ret) - 1) { |
| 620 | $l = mb_strcut($ret, $ptr, $wrap); |
| 621 | $ptr += strlen($l); |
| 622 | $tmp = $l; |
| 623 | |
| 624 | $l = mb_strcut($ret, $ptr, 2); |
| 625 | while (strlen($l) != 0 && mb_strpos($no_begin, $l) !== FALSE ) { |
| 626 | $tmp .= $l; |
| 627 | $ptr += strlen($l); |
| 628 | $l = mb_strcut($ret, $ptr, 1); |
| 629 | } |
| 630 | $line_new .= $tmp; |
| 631 | if ($ptr < strlen($ret) - 1) |
| 632 | $line_new .= "\n"; |
| 633 | } |
| 634 | $ret = $line_new; |
| 635 | } |
| 636 | } |
| 637 | return $ret; |
| 638 | } |
| 639 | |
| 640 | /** |
| 641 | * Japanese imap folder name encoding function |
| 642 | * |
| 643 | * converts folder name from euc-jp to utf7-imap |
| 644 | * @param string $ret folder name |
| 645 | * @return string converted folder name |
| 646 | * @since 1.5.1 |
| 647 | */ |
| 648 | function japanese_xtra_utf7_imap_encode($ret){ |
| 649 | if (function_exists('mb_detect_encoding')) { |
| 650 | $ret = mb_convert_encoding($ret, 'UTF7-IMAP', 'EUC-JP'); |
| 651 | } |
| 652 | return $ret; |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Japanese imap folder name decoding function |
| 657 | * |
| 658 | * converts folder name from utf7-imap to euc-jp. |
| 659 | * @param string $ret folder name in utf7-imap |
| 660 | * @return string converted folder name |
| 661 | * @since 1.5.1 |
| 662 | */ |
| 663 | function japanese_xtra_utf7_imap_decode($ret) { |
| 664 | if (function_exists('mb_detect_encoding')) { |
| 665 | $ret = mb_convert_encoding($ret, 'EUC-JP', 'UTF7-IMAP'); |
| 666 | } |
| 667 | return $ret; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Japanese string trimming function |
| 672 | * |
| 673 | * trims string to defined number of symbols |
| 674 | * @param string $ret string |
| 675 | * @param integer $width number of symbols |
| 676 | * @return string trimmed string |
| 677 | * @since 1.5.1 |
| 678 | */ |
| 679 | function japanese_xtra_strimwidth($ret,$width) { |
| 680 | if (function_exists('mb_detect_encoding')) { |
| 681 | $ret = mb_strimwidth($ret, 0, $width, '...'); |
| 682 | } |
| 683 | return $ret; |
| 684 | } |
| 685 | |
| 686 | /******************************** |
| 687 | * Korean charset extra functions |
| 688 | ********************************/ |
| 689 | |
| 690 | /** |
| 691 | * Korean downloaded filename processing functions |
| 692 | * |
| 693 | * @param string default return value |
| 694 | * @return string |
| 695 | * @since 1.5.1 |
| 696 | */ |
| 697 | function korean_xtra_downloadfilename($ret) { |
| 698 | $ret = str_replace("\x0D\x0A", '', $ret); /* Hanmail's CR/LF Clear */ |
| 699 | for ($i=0;$i<strlen($ret);$i++) { |
| 700 | if ($ret[$i] >= "\xA1" && $ret[$i] <= "\xFE") { /* 0xA1 - 0XFE are Valid */ |
| 701 | $i++; |
| 702 | continue; |
| 703 | } else if (($ret[$i] >= 'a' && $ret[$i] <= 'z') || /* From Original ereg_replace in download.php */ |
| 704 | ($ret[$i] >= 'A' && $ret[$i] <= 'Z') || |
| 705 | ($ret[$i] == '.') || ($ret[$i] == '-')) { |
| 706 | continue; |
| 707 | } else { |
| 708 | $ret[$i] = '_'; |
| 709 | } |
| 710 | } |
| 711 | return $ret; |
| 712 | } |
| 713 | |
| 714 | /** |
| 715 | * Replaces non-braking spaces inserted by some browsers with regular space |
| 716 | * |
| 717 | * This function can be used to replace non-braking space symbols |
| 718 | * that are inserted in forms by some browsers instead of normal |
| 719 | * space symbol. |
| 720 | * |
| 721 | * @param string $string Text that needs to be cleaned |
| 722 | * @param string $charset Charset used in text |
| 723 | * @return string Cleaned text |
| 724 | */ |
| 725 | function cleanup_nbsp($string,$charset) { |
| 726 | |
| 727 | // reduce number of case statements |
| 728 | if (stristr('iso-8859-',substr($charset,0,9))){ |
| 729 | $output_charset="iso-8859-x"; |
| 730 | } |
| 731 | if (stristr('windows-125',substr($charset,0,11))){ |
| 732 | $output_charset="cp125x"; |
| 733 | } |
| 734 | if (stristr('koi8',substr($charset,0,4))){ |
| 735 | $output_charset="koi8-x"; |
| 736 | } |
| 737 | if (! isset($output_charset)){ |
| 738 | $output_charset=strtolower($charset); |
| 739 | } |
| 740 | |
| 741 | // where is non-braking space symbol |
| 742 | switch($output_charset): |
| 743 | case "iso-8859-x": |
| 744 | case "cp125x": |
| 745 | case "iso-2022-jp": |
| 746 | $nbsp="\xA0"; |
| 747 | break; |
| 748 | case "koi8-x": |
| 749 | $nbsp="\x9A"; |
| 750 | break; |
| 751 | case "utf-8": |
| 752 | $nbsp="\xC2\xA0"; |
| 753 | break; |
| 754 | default: |
| 755 | // don't change string if charset is unmatched |
| 756 | return $string; |
| 757 | endswitch; |
| 758 | |
| 759 | // return space instead of non-braking space. |
| 760 | return str_replace($nbsp,' ',$string); |
| 761 | } |
| 762 | |
| 763 | /** |
| 764 | * Function informs if it is safe to convert given charset to the one that is used by user. |
| 765 | * |
| 766 | * It is safe to use conversion only if user uses utf-8 encoding and when |
| 767 | * converted charset is similar to the one that is used by user. |
| 768 | * |
| 769 | * @param string $input_charset Charset of text that needs to be converted |
| 770 | * @return bool is it possible to convert to user's charset |
| 771 | */ |
| 772 | function is_conversion_safe($input_charset) { |
| 773 | global $languages, $sm_notAlias, $default_charset, $lossy_encoding; |
| 774 | |
| 775 | if (isset($lossy_encoding) && $lossy_encoding ) |
| 776 | return true; |
| 777 | |
| 778 | // convert to lower case |
| 779 | $input_charset = strtolower($input_charset); |
| 780 | |
| 781 | // Is user's locale Unicode based ? |
| 782 | if ( $default_charset == "utf-8" ) { |
| 783 | return true; |
| 784 | } |
| 785 | |
| 786 | // Charsets that are similar |
| 787 | switch ($default_charset): |
| 788 | case "windows-1251": |
| 789 | if ( $input_charset == "iso-8859-5" || |
| 790 | $input_charset == "koi8-r" || |
| 791 | $input_charset == "koi8-u" ) { |
| 792 | return true; |
| 793 | } else { |
| 794 | return false; |
| 795 | } |
| 796 | case "windows-1257": |
| 797 | if ( $input_charset == "iso-8859-13" || |
| 798 | $input_charset == "iso-8859-4" ) { |
| 799 | return true; |
| 800 | } else { |
| 801 | return false; |
| 802 | } |
| 803 | case "iso-8859-4": |
| 804 | if ( $input_charset == "iso-8859-13" || |
| 805 | $input_charset == "windows-1257" ) { |
| 806 | return true; |
| 807 | } else { |
| 808 | return false; |
| 809 | } |
| 810 | case "iso-8859-5": |
| 811 | if ( $input_charset == "windows-1251" || |
| 812 | $input_charset == "koi8-r" || |
| 813 | $input_charset == "koi8-u" ) { |
| 814 | return true; |
| 815 | } else { |
| 816 | return false; |
| 817 | } |
| 818 | case "iso-8859-13": |
| 819 | if ( $input_charset == "iso-8859-4" || |
| 820 | $input_charset == "windows-1257" ) { |
| 821 | return true; |
| 822 | } else { |
| 823 | return false; |
| 824 | } |
| 825 | case "koi8-r": |
| 826 | if ( $input_charset == "windows-1251" || |
| 827 | $input_charset == "iso-8859-5" || |
| 828 | $input_charset == "koi8-u" ) { |
| 829 | return true; |
| 830 | } else { |
| 831 | return false; |
| 832 | } |
| 833 | case "koi8-u": |
| 834 | if ( $input_charset == "windows-1251" || |
| 835 | $input_charset == "iso-8859-5" || |
| 836 | $input_charset == "koi8-r" ) { |
| 837 | return true; |
| 838 | } else { |
| 839 | return false; |
| 840 | } |
| 841 | default: |
| 842 | return false; |
| 843 | endswitch; |
| 844 | } |
| 845 | |
| 846 | |
| 847 | /* ------------------------------ main --------------------------- */ |
| 848 | |
| 849 | global $squirrelmail_language, $languages, $use_gettext; |
| 850 | |
| 851 | if (! isset($squirrelmail_language)) { |
| 852 | $squirrelmail_language = ''; |
| 853 | } |
| 854 | |
| 855 | /** |
| 856 | * Array specifies the available translations. |
| 857 | * |
| 858 | * Structure of array: |
| 859 | * $languages['language']['variable'] = 'value' |
| 860 | * |
| 861 | * Possible 'variable' names: |
| 862 | * NAME - Translation name in English |
| 863 | * CHARSET - Encoding used by translation |
| 864 | * ALIAS - used when 'language' is only short name and 'value' should provide long language name |
| 865 | * ALTNAME - Native translation name. Any 8bit symbols must be html encoded. |
| 866 | * LOCALE - Full locale name (in xx_XX.charset format) |
| 867 | * DIR - Text direction. Used to define Right-to-Left languages. Possible values 'rtl' or 'ltr'. If undefined - defaults to 'ltr' |
| 868 | * XTRA_CODE - translation uses special functions. See doc/i18n.txt |
| 869 | * |
| 870 | * Each 'language' definition requires NAME+CHARSET or ALIAS variables. |
| 871 | * |
| 872 | * @name $languages |
| 873 | * @global array $languages |
| 874 | */ |
| 875 | $languages['bg_BG']['NAME'] = 'Bulgarian'; |
| 876 | $languages['bg_BG']['ALTNAME'] = 'Български'; |
| 877 | $languages['bg_BG']['CHARSET'] = 'windows-1251'; |
| 878 | $languages['bg_BG']['LOCALE'] = 'bg_BG.CP1251'; |
| 879 | $languages['bg']['ALIAS'] = 'bg_BG'; |
| 880 | |
| 881 | $languages['bn_IN']['NAME'] = 'Bengali'; |
| 882 | $languages['bn_IN']['CHARSET'] = 'utf-8'; |
| 883 | $languages['bn_IN']['LOCALE'] = 'bn_IN.UTF-8'; |
| 884 | $languages['bn_BD']['ALIAS'] = 'bn_IN'; |
| 885 | $languages['bn']['ALIAS'] = 'bn_IN'; |
| 886 | |
| 887 | $languages['ca_ES']['NAME'] = 'Catalan'; |
| 888 | $languages['ca_ES']['CHARSET'] = 'iso-8859-1'; |
| 889 | $languages['ca_ES']['LOCALE'] = array('ca_ES.ISO8859-1','ca_ES.ISO-8859-1','ca_ES'); |
| 890 | $languages['ca']['ALIAS'] = 'ca_ES'; |
| 891 | |
| 892 | $languages['cs_CZ']['NAME'] = 'Czech'; |
| 893 | $languages['cs_CZ']['ALTNAME'] = 'Čeština'; |
| 894 | $languages['cs_CZ']['CHARSET'] = 'iso-8859-2'; |
| 895 | $languages['cs_CZ']['LOCALE'] = array('cs_CZ.ISO8859-2','cs_CZ.ISO-8859-2','cs_CZ'); |
| 896 | $languages['cs']['ALIAS'] = 'cs_CZ'; |
| 897 | |
| 898 | $languages['cy_GB']['NAME'] = 'Welsh'; |
| 899 | $languages['cy_GB']['ALTNAME'] = 'Cymraeg'; |
| 900 | $languages['cy_GB']['CHARSET'] = 'iso-8859-1'; |
| 901 | $languages['cy_GB']['LOCALE'] = array('cy_GB.ISO8859-1','cy_GB.ISO-8859-1','cy_GB'); |
| 902 | $languages['cy']['ALIAS'] = 'cy_GB'; |
| 903 | |
| 904 | // Danish locale is da_DK. |
| 905 | $languages['da_DK']['NAME'] = 'Danish'; |
| 906 | $languages['da_DK']['ALTNAME'] = 'Dansk'; |
| 907 | $languages['da_DK']['CHARSET'] = 'iso-8859-1'; |
| 908 | $languages['da_DK']['LOCALE'] = array('da_DK.ISO8859-1','da_DK.ISO-8859-1','da_DK'); |
| 909 | $languages['da']['ALIAS'] = 'da_DK'; |
| 910 | |
| 911 | $languages['de_DE']['NAME'] = 'German'; |
| 912 | $languages['de_DE']['ALTNAME'] = 'Deutsch'; |
| 913 | $languages['de_DE']['CHARSET'] = 'iso-8859-1'; |
| 914 | $languages['de_DE']['LOCALE'] = array('de_DE.ISO8859-1','de_DE.ISO-8859-1','de_DE'); |
| 915 | $languages['de']['ALIAS'] = 'de_DE'; |
| 916 | |
| 917 | $languages['el_GR']['NAME'] = 'Greek'; |
| 918 | $languages['el_GR']['ALTNAME'] = 'Ελληνικά'; |
| 919 | $languages['el_GR']['CHARSET'] = 'iso-8859-7'; |
| 920 | $languages['el_GR']['LOCALE'] = array('el_GR.ISO8859-7','el_GR.ISO-8859-7','el_GR'); |
| 921 | $languages['el']['ALIAS'] = 'el_GR'; |
| 922 | |
| 923 | $languages['en_GB']['NAME'] = 'British'; |
| 924 | $languages['en_GB']['CHARSET'] = 'iso-8859-15'; |
| 925 | $languages['en_GB']['LOCALE'] = array('en_GB.ISO8859-15','en_GB.ISO-8859-15','en_GB'); |
| 926 | |
| 927 | $languages['en_US']['NAME'] = 'English'; |
| 928 | $languages['en_US']['CHARSET'] = 'iso-8859-1'; |
| 929 | $languages['en_US']['LOCALE'] = 'en_US.ISO8859-1'; |
| 930 | $languages['en']['ALIAS'] = 'en_US'; |
| 931 | |
| 932 | $languages['es_ES']['NAME'] = 'Spanish'; |
| 933 | $languages['es_ES']['ALTNAME'] = 'Español'; |
| 934 | $languages['es_ES']['CHARSET'] = 'iso-8859-1'; |
| 935 | $languages['es_ES']['LOCALE'] = array('es_ES.ISO8859-1','es_ES.ISO-8859-1','es_ES'); |
| 936 | $languages['es']['ALIAS'] = 'es_ES'; |
| 937 | |
| 938 | $languages['et_EE']['NAME'] = 'Estonian'; |
| 939 | $languages['et_EE']['CHARSET'] = 'iso-8859-15'; |
| 940 | $languages['et_EE']['LOCALE'] = array('et_EE.ISO8859-15','et_EE.ISO-8859-15','et_EE'); |
| 941 | $languages['et']['ALIAS'] = 'et_EE'; |
| 942 | |
| 943 | $languages['eu_ES']['NAME'] = 'Basque'; |
| 944 | $languages['eu_ES']['CHARSET'] = 'iso-8859-1'; |
| 945 | $languages['eu_ES']['LOCALE'] = array('eu_ES.ISO8859-1','eu_ES.ISO-8859-1','eu_ES'); |
| 946 | $languages['eu']['ALIAS'] = 'eu_ES'; |
| 947 | |
| 948 | $languages['fo_FO']['NAME'] = 'Faroese'; |
| 949 | $languages['fo_FO']['CHARSET'] = 'iso-8859-1'; |
| 950 | $languages['fo_FO']['LOCALE'] = array('fo_FO.ISO8859-1','fo_FO.ISO-8859-1','fo_FO'); |
| 951 | $languages['fo']['ALIAS'] = 'fo_FO'; |
| 952 | |
| 953 | $languages['fi_FI']['NAME'] = 'Finnish'; |
| 954 | $languages['fi_FI']['ALTNAME'] = 'Suomi'; |
| 955 | $languages['fi_FI']['CHARSET'] = 'iso-8859-1'; |
| 956 | $languages['fi_FI']['LOCALE'] = array('fi_FI.ISO8859-1','fi_FI.ISO-8859-1','fi_FI'); |
| 957 | $languages['fi']['ALIAS'] = 'fi_FI'; |
| 958 | |
| 959 | $languages['fr_FR']['NAME'] = 'French'; |
| 960 | $languages['fr_FR']['ALTNAME'] = 'Français'; |
| 961 | $languages['fr_FR']['CHARSET'] = 'iso-8859-1'; |
| 962 | $languages['fr_FR']['LOCALE'] = array('fr_FR.ISO8859-1','fr_FR.ISO-8859-1','fr_FR'); |
| 963 | $languages['fr']['ALIAS'] = 'fr_FR'; |
| 964 | |
| 965 | $languages['hr_HR']['NAME'] = 'Croatian'; |
| 966 | $languages['hr_HR']['CHARSET'] = 'iso-8859-2'; |
| 967 | $languages['hr_HR']['LOCALE'] = array('hr_HR.ISO8859-2','hr_HR.ISO-8859-2','hr_HR'); |
| 968 | $languages['hr']['ALIAS'] = 'hr_HR'; |
| 969 | |
| 970 | $languages['hu_HU']['NAME'] = 'Hungarian'; |
| 971 | $languages['hu_HU']['ALTNAME'] = 'Magyar'; |
| 972 | $languages['hu_HU']['CHARSET'] = 'iso-8859-2'; |
| 973 | $languages['hu_HU']['LOCALE'] = array('hu_HU.ISO8859-2','hu_HU.ISO-8859-2','hu_HU'); |
| 974 | $languages['hu']['ALIAS'] = 'hu_HU'; |
| 975 | |
| 976 | $languages['id_ID']['NAME'] = 'Indonesian'; |
| 977 | $languages['id_ID']['ALTNAME'] = 'Bahasa Indonesia'; |
| 978 | $languages['id_ID']['CHARSET'] = 'iso-8859-1'; |
| 979 | $languages['id_ID']['LOCALE'] = array('id_ID.ISO8859-1','id_ID.ISO-8859-1','id_ID'); |
| 980 | $languages['id']['ALIAS'] = 'id_ID'; |
| 981 | |
| 982 | $languages['is_IS']['NAME'] = 'Icelandic'; |
| 983 | $languages['is_IS']['ALTNAME'] = 'Íslenska'; |
| 984 | $languages['is_IS']['CHARSET'] = 'iso-8859-1'; |
| 985 | $languages['is_IS']['LOCALE'] = array('is_IS.ISO8859-1','is_IS.ISO-8859-1','is_IS'); |
| 986 | $languages['is']['ALIAS'] = 'is_IS'; |
| 987 | |
| 988 | $languages['it_IT']['NAME'] = 'Italian'; |
| 989 | $languages['it_IT']['CHARSET'] = 'iso-8859-1'; |
| 990 | $languages['it_IT']['LOCALE'] = array('it_IT.ISO8859-1','it_IT.ISO-8859-1','it_IT'); |
| 991 | $languages['it']['ALIAS'] = 'it_IT'; |
| 992 | |
| 993 | $languages['ja_JP']['NAME'] = 'Japanese'; |
| 994 | $languages['ja_JP']['ALTNAME'] = '日本語'; |
| 995 | $languages['ja_JP']['CHARSET'] = 'iso-2022-jp'; |
| 996 | $languages['ja_JP']['LOCALE'] = 'ja_JP.EUC-JP'; |
| 997 | $languages['ja_JP']['XTRA_CODE'] = 'japanese_xtra'; |
| 998 | $languages['ja']['ALIAS'] = 'ja_JP'; |
| 999 | |
| 1000 | $languages['ko_KR']['NAME'] = 'Korean'; |
| 1001 | $languages['ko_KR']['CHARSET'] = 'euc-KR'; |
| 1002 | $languages['ko_KR']['LOCALE'] = 'ko_KR.EUC-KR'; |
| 1003 | $languages['ko_KR']['XTRA_CODE'] = 'korean_xtra'; |
| 1004 | $languages['ko']['ALIAS'] = 'ko_KR'; |
| 1005 | |
| 1006 | $languages['lt_LT']['NAME'] = 'Lithuanian'; |
| 1007 | $languages['lt_LT']['ALTNAME'] = 'Lietuvių'; |
| 1008 | $languages['lt_LT']['CHARSET'] = 'utf-8'; |
| 1009 | $languages['lt_LT']['LOCALE'] = 'lt_LT.UTF-8'; |
| 1010 | $languages['lt']['ALIAS'] = 'lt_LT'; |
| 1011 | |
| 1012 | $languages['nl_NL']['NAME'] = 'Dutch'; |
| 1013 | $languages['nl_NL']['ALTNAME'] = 'Nederlands'; |
| 1014 | $languages['nl_NL']['CHARSET'] = 'iso-8859-1'; |
| 1015 | $languages['nl_NL']['LOCALE'] = array('nl_NL.ISO8859-1','nl_NL.ISO-8859-1','nl_NL'); |
| 1016 | $languages['nl']['ALIAS'] = 'nl_NL'; |
| 1017 | |
| 1018 | $languages['ms_MY']['NAME'] = 'Malay'; |
| 1019 | $languages['ms_MY']['ALTNAME'] = 'Bahasa Melayu'; |
| 1020 | $languages['ms_MY']['CHARSET'] = 'iso-8859-1'; |
| 1021 | $languages['ms_MY']['LOCALE'] = array('ms_MY.ISO8859-1','ms_MY.ISO-8859-1','ms_MY'); |
| 1022 | $languages['my']['ALIAS'] = 'ms_MY'; |
| 1023 | |
| 1024 | $languages['nb_NO']['NAME'] = 'Norwegian (Bokmål)'; |
| 1025 | $languages['nb_NO']['ALTNAME'] = 'Norsk (Bokmål)'; |
| 1026 | $languages['nb_NO']['CHARSET'] = 'iso-8859-1'; |
| 1027 | $languages['nb_NO']['LOCALE'] = array('nb_NO.ISO8859-1','nb_NO.ISO-8859-1','nb_NO'); |
| 1028 | $languages['nb']['ALIAS'] = 'nb_NO'; |
| 1029 | |
| 1030 | $languages['nn_NO']['NAME'] = 'Norwegian (Nynorsk)'; |
| 1031 | $languages['nn_NO']['ALTNAME'] = 'Norsk (Nynorsk)'; |
| 1032 | $languages['nn_NO']['CHARSET'] = 'iso-8859-1'; |
| 1033 | $languages['nn_NO']['LOCALE'] = array('nn_NO.ISO8859-1','nn_NO.ISO-8859-1','nn_NO'); |
| 1034 | |
| 1035 | $languages['pl_PL']['NAME'] = 'Polish'; |
| 1036 | $languages['pl_PL']['ALTNAME'] = 'Polski'; |
| 1037 | $languages['pl_PL']['CHARSET'] = 'iso-8859-2'; |
| 1038 | $languages['pl_PL']['LOCALE'] = array('pl_PL.ISO8859-2','pl_PL.ISO-8859-2','pl_PL'); |
| 1039 | $languages['pl']['ALIAS'] = 'pl_PL'; |
| 1040 | |
| 1041 | $languages['pt_PT']['NAME'] = 'Portuguese (Portugal)'; |
| 1042 | $languages['pt_PT']['CHARSET'] = 'iso-8859-1'; |
| 1043 | $languages['pt_PT']['LOCALE'] = array('pt_PT.ISO8859-1','pt_PT.ISO-8859-1','pt_PT'); |
| 1044 | $languages['pt']['ALIAS'] = 'pt_PT'; |
| 1045 | |
| 1046 | $languages['pt_BR']['NAME'] = 'Portuguese (Brazil)'; |
| 1047 | $languages['pt_BR']['ALTNAME'] = 'Português do Brasil'; |
| 1048 | $languages['pt_BR']['CHARSET'] = 'iso-8859-1'; |
| 1049 | $languages['pt_BR']['LOCALE'] = array('pt_BR.ISO8859-1','pt_BR.ISO-8859-1','pt_BR'); |
| 1050 | |
| 1051 | $languages['ro_RO']['NAME'] = 'Romanian'; |
| 1052 | $languages['ro_RO']['ALTNAME'] = 'Română'; |
| 1053 | $languages['ro_RO']['CHARSET'] = 'iso-8859-2'; |
| 1054 | $languages['ro_RO']['LOCALE'] = array('ro_RO.ISO8859-2','ro_RO.ISO-8859-2','ro_RO'); |
| 1055 | $languages['ro']['ALIAS'] = 'ro_RO'; |
| 1056 | |
| 1057 | $languages['ru_RU']['NAME'] = 'Russian'; |
| 1058 | $languages['ru_RU']['ALTNAME'] = 'Русский'; |
| 1059 | $languages['ru_RU']['CHARSET'] = 'utf-8'; |
| 1060 | $languages['ru_RU']['LOCALE'] = 'ru_RU.UTF-8'; |
| 1061 | $languages['ru']['ALIAS'] = 'ru_RU'; |
| 1062 | |
| 1063 | $languages['sk_SK']['NAME'] = 'Slovak'; |
| 1064 | $languages['sk_SK']['CHARSET'] = 'iso-8859-2'; |
| 1065 | $languages['sk_SK']['LOCALE'] = array('sk_SK.ISO8859-2','sk_SK.ISO-8859-2','sk_SK'); |
| 1066 | $languages['sk']['ALIAS'] = 'sk_SK'; |
| 1067 | |
| 1068 | $languages['sl_SI']['NAME'] = 'Slovenian'; |
| 1069 | $languages['sl_SI']['ALTNAME'] = 'Slovenščina'; |
| 1070 | $languages['sl_SI']['CHARSET'] = 'iso-8859-2'; |
| 1071 | $languages['sl_SI']['LOCALE'] = array('sl_SI.ISO8859-2','sl_SI.ISO-8859-2','sl_SI'); |
| 1072 | $languages['sl']['ALIAS'] = 'sl_SI'; |
| 1073 | |
| 1074 | $languages['sr_YU']['NAME'] = 'Serbian'; |
| 1075 | $languages['sr_YU']['ALTNAME'] = 'Srpski'; |
| 1076 | $languages['sr_YU']['CHARSET'] = 'iso-8859-2'; |
| 1077 | $languages['sr_YU']['LOCALE'] = array('sr_YU.ISO8859-2','sr_YU.ISO-8859-2','sr_YU'); |
| 1078 | $languages['sr']['ALIAS'] = 'sr_YU'; |
| 1079 | |
| 1080 | $languages['sv_SE']['NAME'] = 'Swedish'; |
| 1081 | $languages['sv_SE']['ALTNAME'] = 'Svenska'; |
| 1082 | $languages['sv_SE']['CHARSET'] = 'iso-8859-1'; |
| 1083 | $languages['sv_SE']['LOCALE'] = array('sv_SE.ISO8859-1','sv_SE.ISO-8859-1','sv_SE'); |
| 1084 | $languages['sv']['ALIAS'] = 'sv_SE'; |
| 1085 | |
| 1086 | $languages['th_TH']['NAME'] = 'Thai'; |
| 1087 | $languages['th_TH']['CHARSET'] = 'tis-620'; |
| 1088 | $languages['th_TH']['LOCALE'] = 'th_TH.TIS-620'; |
| 1089 | $languages['th']['ALIAS'] = 'th_TH'; |
| 1090 | |
| 1091 | $languages['tl_PH']['NAME'] = 'Tagalog'; |
| 1092 | $languages['tl_PH']['CHARSET'] = 'iso-8859-1'; |
| 1093 | $languages['tl_PH']['LOCALE'] = array('tl_PH.ISO8859-1','tl_PH.ISO-8859-1','tl_PH'); |
| 1094 | $languages['tl']['ALIAS'] = 'tl_PH'; |
| 1095 | |
| 1096 | $languages['tr_TR']['NAME'] = 'Turkish'; |
| 1097 | $languages['tr_TR']['CHARSET'] = 'iso-8859-9'; |
| 1098 | $languages['tr_TR']['LOCALE'] = array('tr_TR.ISO8859-9','tr_TR.ISO-8859-9','tr_TR'); |
| 1099 | $languages['tr']['ALIAS'] = 'tr_TR'; |
| 1100 | |
| 1101 | $languages['zh_TW']['NAME'] = 'Chinese Trad'; |
| 1102 | $languages['zh_TW']['CHARSET'] = 'big5'; |
| 1103 | $languages['zh_TW']['LOCALE'] = 'zh_TW.BIG5'; |
| 1104 | $languages['tw']['ALIAS'] = 'zh_TW'; |
| 1105 | |
| 1106 | $languages['zh_CN']['NAME'] = 'Chinese Simp'; |
| 1107 | $languages['zh_CN']['CHARSET'] = 'gb2312'; |
| 1108 | $languages['zh_CN']['LOCALE'] = 'zh_CN.GB2312'; |
| 1109 | $languages['cn']['ALIAS'] = 'zh_CN'; |
| 1110 | |
| 1111 | $languages['uk_UA']['NAME'] = 'Ukrainian'; |
| 1112 | $languages['uk_UA']['CHARSET'] = 'koi8-u'; |
| 1113 | $languages['uk_UA']['LOCALE'] = 'uk_UA.KOI8-U'; |
| 1114 | $languages['uk']['ALIAS'] = 'uk_UA'; |
| 1115 | |
| 1116 | $languages['ru_UA']['NAME'] = 'Russian (Ukrainian)'; |
| 1117 | $languages['ru_UA']['CHARSET'] = 'koi8-r'; |
| 1118 | $languages['ru_UA']['LOCALE'] = 'ru_UA.KOI8-R'; |
| 1119 | |
| 1120 | /* |
| 1121 | $languages['vi_VN']['NAME'] = 'Vietnamese'; |
| 1122 | $languages['vi_VN']['CHARSET'] = 'utf-8'; |
| 1123 | $languages['vi']['ALIAS'] = 'vi_VN'; |
| 1124 | */ |
| 1125 | |
| 1126 | // Right to left languages |
| 1127 | $languages['ar']['NAME'] = 'Arabic'; |
| 1128 | $languages['ar']['CHARSET'] = 'windows-1256'; |
| 1129 | $languages['ar']['DIR'] = 'rtl'; |
| 1130 | |
| 1131 | $languages['fa_IR']['NAME'] = 'Farsi'; |
| 1132 | $languages['fa_IR']['CHARSET'] = 'utf-8'; |
| 1133 | $languages['fa_IR']['DIR'] = 'rtl'; |
| 1134 | $languages['fa_IR']['LOCALE'] = 'fa_IR.UTF-8'; |
| 1135 | $languages['fa']['ALIAS'] = 'fa_IR'; |
| 1136 | |
| 1137 | $languages['he_IL']['NAME'] = 'Hebrew'; |
| 1138 | $languages['he_IL']['CHARSET'] = 'windows-1255'; |
| 1139 | $languages['he_IL']['LOCALE'] = 'he_IL.CP1255'; |
| 1140 | $languages['he_IL']['DIR'] = 'rtl'; |
| 1141 | $languages['he']['ALIAS'] = 'he_IL'; |
| 1142 | |
| 1143 | $languages['ug']['NAME'] = 'Uighur'; |
| 1144 | $languages['ug']['CHARSET'] = 'utf-8'; |
| 1145 | $languages['ug']['DIR'] = 'rtl'; |
| 1146 | |
| 1147 | /* Detect whether gettext is installed. */ |
| 1148 | $gettext_flags = 0; |
| 1149 | if (function_exists('_')) { |
| 1150 | $gettext_flags += 1; |
| 1151 | } |
| 1152 | if (function_exists('bindtextdomain')) { |
| 1153 | $gettext_flags += 2; |
| 1154 | } |
| 1155 | if (function_exists('textdomain')) { |
| 1156 | $gettext_flags += 4; |
| 1157 | } |
| 1158 | if (function_exists('ngettext')) { |
| 1159 | $gettext_flags += 8; |
| 1160 | } |
| 1161 | |
| 1162 | /* If gettext is fully loaded, cool */ |
| 1163 | if ($gettext_flags == 15) { |
| 1164 | $use_gettext = true; |
| 1165 | } |
| 1166 | |
| 1167 | /* If ngettext support is missing, load it */ |
| 1168 | elseif ($gettext_flags == 7) { |
| 1169 | $use_gettext = true; |
| 1170 | // load internal ngettext functions |
| 1171 | include_once(SM_PATH . 'class/l10n.class.php'); |
| 1172 | include_once(SM_PATH . 'functions/ngettext.php'); |
| 1173 | } |
| 1174 | |
| 1175 | /* If we can fake gettext, try that */ |
| 1176 | elseif ($gettext_flags == 0) { |
| 1177 | $use_gettext = true; |
| 1178 | include_once(SM_PATH . 'functions/gettext.php'); |
| 1179 | } else { |
| 1180 | /* Uh-ho. A weird install */ |
| 1181 | if (! $gettext_flags & 1) { |
| 1182 | /** |
| 1183 | * Function is used as replacement in broken installs |
| 1184 | * @ignore |
| 1185 | */ |
| 1186 | function _($str) { |
| 1187 | return $str; |
| 1188 | } |
| 1189 | } |
| 1190 | if (! $gettext_flags & 2) { |
| 1191 | /** |
| 1192 | * Function is used as replacement in broken installs |
| 1193 | * @ignore |
| 1194 | */ |
| 1195 | function bindtextdomain() { |
| 1196 | return; |
| 1197 | } |
| 1198 | } |
| 1199 | if (! $gettext_flags & 4) { |
| 1200 | /** |
| 1201 | * Function is used as replacemet in broken installs |
| 1202 | * @ignore |
| 1203 | */ |
| 1204 | function textdomain() { |
| 1205 | return; |
| 1206 | } |
| 1207 | } |
| 1208 | if (! $gettext_flags & 8) { |
| 1209 | /** |
| 1210 | * Function is used as replacemet in broken installs |
| 1211 | * @ignore |
| 1212 | */ |
| 1213 | function ngettext($str,$str2,$number) { |
| 1214 | if ($number>1) { |
| 1215 | return $str2; |
| 1216 | } else { |
| 1217 | return $str; |
| 1218 | } |
| 1219 | } |
| 1220 | } |
| 1221 | } |
| 1222 | ?> |