$value ) { if ( !is_array($value) ) { $array[$key] = self::convert($value, $from, $to); } else { self::convert_array($array[$key]); } } } return $array; } /** * i18n::strlen * strlen wrapper * * @static * @param string $string target string * @return integer the number of letters */ static public function strlen($string) { $length = 0; if ( self::$mode == 'iconv' ) { $length = iconv_strlen($string, self::$current_charset); } else if ( self::$mode == 'mbstring' ) { $length = mb_strlen($string, self::$current_charset); } else { $length = strlen($string); } return (integer) $length; } /** * i18n::strpos * strpos wrapper * * @static * @param string $haystack string to search * @param string $needle string for search * @param integer $offset the position from which the search should be performed. * @return integer/FALSE the numeric position of the first occurrence of needle in haystack */ static public function strpos($haystack, $needle, $offset=0) { $position = 0; if ( self::$mode == 'iconv' ) { $position = iconv_strpos($haystack, $needle, $offset, self::$current_charset); } else if ( self::$mode == 'mbstring' ) { $position = mb_strpos($haystack, $needle, $offset, self::$current_charset); } else { $position = strpos($haystack, $needle, $offset); } if ( $position !== FALSE) { $position = (integer) $position; } return $position; } /** * i18n::strrpos * strrpos wrapper * * @static * @param string $haystack string to search * @param string $needle string for search * @return integer/FALSE the numeric position of the last occurrence of needle in haystack */ static public function strrpos ($haystack, $needle) { $position = 0; if ( self::$mode == 'iconv' ) { $position = iconv_strrpos($haystack, $needle, self::$current_charset); } else if ( self::$mode == 'mbstring' ) { $position = mb_strrpos($haystack, $needle, 0, self::$current_charset); } else { $position = strrpos($haystack, $needle, 0); } if ( $position !== FALSE) { $position = (integer) $position; } return $position; } /** * i18n::substr * substr wrapper * * @static * @param string $string string to be cut * @param string $start the position of starting * @param integer $length the length to be cut * @return string the extracted part of string */ static public function substr($string, $start, $length=0) { $return = ''; if ( $length == 0 ) { $length = self::strlen($string) - $start; } if ( self::$mode == 'iconv' ) { $return = iconv_substr($string, $start, $length, self::$current_charset); } else if ( self::$mode == 'mbstring' ) { $return = mb_substr($string, $start, $length, self::$current_charset); } else { $return = strrpos($string, $start, $length); } return (string) $return; } /** * i18n::strftime * strftime function based on multibyte processing * * @static * @param string $format format with singlebyte or multibyte * @param timestamp $timestamp UNIX timestamp * @return string formatted timestamp */ static public function strftime($format, $timestamp='') { return preg_replace_callback('/(%[a-z%])/i', create_function('$matches', 'return strftime($matches[1], ' . intval($timestamp) . ');'), $format ); } /** * i18n::formatted_datetime() * return formatted datetime string * * Date and Time Formats * @link http://www.w3.org/TR/NOTE-datetime * * Working with Time Zones * @link http://www.w3.org/TR/timezone/ * * @param String $format time expression format * @param String $timestamp UNIX timestamp * @param Integer $offset timestamp offset * @return String formatted datetime */ static public function formatted_datetime($format, $timestamp, $offset=0) { $suffix = ''; $string = ''; switch ( $format ) { case 'mysql': /* * MySQL 5.0 Reference Manual * 10.3.1. The DATE, DATETIME, and TIMESTAMP Types * http://dev.mysql.com/doc/refman/5.0/en/datetime.html */ $timestamp += $offset; $format = '%Y-%m-%d %H:%M:%S'; $suffix =''; break; case 'rfc822': /* * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES * 5. DATE AND TIME SPECIFICATION * http://www.ietf.org/rfc/rfc0822.txt */ $format = '%a, %d %m %y %H:%M:%S '; if ( $offset < 0 ) { $suffix = '-'; $offset = -$offset; } else { $suffix = '+'; } $suffix .= sprintf("%02d%02d", floor($offset / 3600), round(($offset % 3600) / 60) ); break; case 'rfc822GMT': /* * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES * 5. DATE AND TIME SPECIFICATION * http://www.ietf.org/rfc/rfc0822.txt */ $format = '%a, %d %m %y %H:%M:%S '; $timestamp -= $offset; $suffix = 'GMT'; break; case 'iso8601': case 'rfc3339': /* * RFC3339: Date and Time on the Internet: Timestamps * 5. Date and Time format * http://www.ietf.org/rfc/rfc3339.txt */ $format = '%Y-%m-%dT%H:%M:%S'; if ( $offset < 0 ) { $suffix = '-'; $offset = -$offset; } else { $suffix = '+'; } $suffix .= sprintf("%02d:%02d", floor($offset / 3600), round(($offset % 3600) / 60) ); break; case 'utc': case 'iso8601UTC': case 'rfc3339UTC': /* * RFC3339: Date and Time on the Internet: Timestamps * 5. Date and Time format * http://www.ietf.org/rfc/rfc3339.txt */ $timestamp -= $offset; $format = '%Y-%m-%dT%H:%M:%SZ'; $suffix = ''; break; case '': $format = '%X %x'; $offset = ''; break; default: $suffix = ''; break; } return i18n::strftime($format, $timestamp) . $suffix; } /** * i18n::convert_locale_to_old_language_file_name() * NOTE: this should be obsoleted near future. * * @static * @param string $target_locale locale name as language_script_region * @return string old translation file name */ static public function convert_locale_to_old_language_file_name($target_locale) { $target_language = ''; foreach ( self::$lang_refs as $language => $locale ) { if ( preg_match('#-#', $language) ) { if ( $target_locale . '.' . self::$current_charset == $locale ) { $target_language = $language; break; } } else if ( $target_locale == $locale ) { $target_language = $language; } } return $target_language; } /** * i18n::convert_old_language_file_name_to_locale() * NOTE: this should be obsoleted near future. * * @static * @param string $target_language old translation file name * @return string locale name as language_script_region */ static public function convert_old_language_file_name_to_locale($target_language) { $target_locale = ''; foreach ( self::$lang_refs as $language => $locale ) { if ( $target_language == $language ) { if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) ) { $target_locale = $match[1]; } else { $target_locale = $locale; } break; } } return $target_locale; } /** * i18n::$lang_refs * reference table to convert old and new way to name translation files. * NOTE: this should be obsoleted as soon as possible. * * @static */ static private $lang_refs = array( "english" => "en_Latn_US", "english-utf8" => "en_Latn_US.UTF-8", "bulgarian" => "bg_Cyrl_BG", "finnish" => "fi_Latn_FU", "catalan" => "ca_Latn_ES", "french" => "fr_Latn_FR", "russian" => "ru_Cyrl_RU", "chinese" => "zh_Hans_CN", "simchinese" => "zh_Hans_CN", "chineseb5" => "zh_Hant_TW", "traditional_chinese" => "zh_Hant_TW", "galego" => "gl_Latn_ES", "german" => "de_Latn_DE", "korean-utf" => "ko_Kore_KR.UTF-8", "korean-euc-kr" => "ko_Kore_KR.EUC-KR", "slovak" => "sk_Latn_SK", "czech" => "cs_Latn_CZ", "hungarian" => "hu_Latn_HU", "latvian" => "lv_Latn_LV", "nederlands" => "nl_Latn_NL", "italiano" => "it_Latn_IT", "persian" => "fa_Arab_IR", "spanish" => "es_Latn_ES", "spanish-utf8" => "es_Latn_ES.UTF-8", "japanese-euc" => "ja_Jpan_JP.EUC-JP", "japanese-utf8" => "ja_Jpan_JP.UTF-8", "portuguese_brazil" => "pt_Latn_BR" ); }