4 * i18n class for Nucleus CMS
\r
5 * written by Takashi Sakamoto as of Feb 03, 2012
\r
7 * This includes wrapper functions of iconv and mbstring
\r
8 * for multibyte processing and includes parameters related to locale.
\r
10 * This program is free software; you can redistribute it and/or
\r
11 * modify it under the terms of the GNU General Public License
\r
12 * as published by the Free Software Foundation; either version 2
\r
13 * of the License, or (at your option) any later version.
\r
14 * (see nucleus/documentation/index.html#license for more info)
\r
16 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
17 * @copyright Copyright (C) 2002-2011 The Nucleus Group
\r
18 * @version $Id: i18n.php 1678 2012-02-26 07:31:36Z sakamocchi $
\r
22 static private $mode = FALSE;
\r
24 static private $current_charset = '';
\r
25 static private $current_language = '';
\r
26 static private $current_script = '';
\r
27 static private $current_region = '';
\r
29 static private $locale_list = array();
\r
30 static private $timezone = 'UTC';
\r
32 static private $forced_charset = '';
\r
33 static private $forced_language = '';
\r
34 static private $forced_script = '';
\r
35 static private $forced_region = '';
\r
39 * Initializing i18n class
\r
42 * @param string $charset character set
\r
45 static public function init($charset, $dir)
\r
47 /* i18n is already initialized */
\r
53 /* make locale list in this Nucleus CMS */
\r
54 if ( ($handle = opendir($dir)) === FALSE )
\r
58 while ($filename = readdir($handle))
\r
60 if (preg_match("#^(.+_.+_.+)\.{$charset}\.php$#", $filename, $matches) )
\r
62 if ( !in_array($matches[1], self::$locale_list) )
\r
64 self::$locale_list[] = $matches[1];
\r
70 /* set i18n backend and validate character set */
\r
71 if ( extension_loaded('iconv') )
\r
73 /* this is just for checking the charset. */
\r
74 if ( iconv_set_encoding('internal_encoding', $charset)
\r
75 && iconv_set_encoding('output_encoding', $charset)
\r
76 && iconv_set_encoding('internal_encoding', $charset) )
\r
78 self::$current_charset = $charset;
\r
79 self::$mode = 'iconv';
\r
82 else if ( extension_loaded('mbstring') )
\r
84 /* this is just for checking the charset. */
\r
85 if ( mb_http_output($charset)
\r
86 && mb_internal_encoding($charset)
\r
87 && mb_regex_encoding($charset) )
\r
89 self::$current_charset = $charset;
\r
90 self::$mode = 'mbstring';
\r
98 * i18n::get_available_locale_list
\r
99 * return available locale list with current charset
\r
103 * @return array available locale list
\r
105 static public function get_available_locale_list()
\r
107 return self::$locale_list;
\r
111 * i18n::get_current_charset
\r
112 * return current charset
\r
116 * @return string $charset current character set
\r
118 static public function get_current_charset()
\r
120 return self::$current_charset;
\r
125 * Set current locale
\r
128 * naming rule is "$language_$script_$region.$charset.php", refer to RFC 5646.
\r
129 * @link http://www.ietf.org/rfc/rfc5646.txt
\r
130 * @see 2. The Language Tag
\r
133 * @param string $locale
\r
134 * @return bool TRUE/FALSE
\r
137 static public function set_current_locale($locale)
\r
139 if ( preg_match('#^(.+)_(.+)_(.+)$#', $locale, $match) )
\r
141 self::$current_language = $match[1];
\r
142 self::$current_script = $match[2];
\r
143 self::$current_region = $match[3];
\r
151 * Get current locale
\r
157 static public function get_current_locale()
\r
159 $elements = array(self::$current_language, self::$current_script, self::$current_region);
\r
160 return implode('_', $elements);
\r
164 * i18n::set_forced_locale()
\r
165 * Set forced locale
\r
168 * @param string $forced_locale
\r
169 * @return bool TRUE/FALSE
\r
172 static public function set_forced_locale($forced_locale)
\r
174 if ( preg_match('#^(.+)_(.+)_(.+)$#', $forced_locale, $match) )
\r
176 self::$forced_language = $match[1];
\r
177 self::$forced_script = $match[2];
\r
178 self::$forced_region = $match[3];
\r
185 * i18n::get_forced_locale
\r
186 * Get forced locale
\r
190 * @return $forced_locale
\r
192 static public function get_forced_locale()
\r
194 if ( !self::$forced_language )
\r
199 $elements = array(self::$forced_language, self::$forced_script, self::$forced_region);
\r
200 return implode('_', $elements);
\r
204 * i18n::set_forced_charset
\r
205 * return forced charset
\r
208 * @param void $charset forced character set
\r
211 static public function set_forced_charset($forced_charset)
\r
213 self::$forced_charset = $forced_charset;
\r
218 * i18n::get_forced_charset
\r
219 * return forced charset
\r
223 * @return string $charset forced character set
\r
225 static public function get_forced_charset()
\r
227 return self::$forced_charset;
\r
231 * i18n::confirm_default_date_timezone
\r
232 * to avoid E_NOTICE or E_WARNING generated when every calling to a date/time function.
\r
235 * Some private servers are lack of its timezone setting
\r
236 * http://www.php.net/manual/en/function.date-default-timezone-set.php
\r
242 static public function confirm_default_date_timezone()
\r
244 if ( function_exists('date_default_timezone_get')
\r
245 && FALSE !== ($timezone = @date_default_timezone_get()))
\r
247 self::$timezone = $timezone;
\r
249 if (function_exists('date_default_timezone_set')) {
\r
250 @date_default_timezone_set(self::$timezone);
\r
256 * i18n::get_current_date_timezone()
\r
257 * get current timezone
\r
261 * @return $timezone
\r
263 static public function get_date_timezone()
\r
265 return self::$timezone;
\r
270 * character set converter
\r
273 * @param string $string target string binary
\r
274 * @param string $from original character set encoding
\r
275 * @param string $to target character set encoding
\r
276 * @return string converted string
\r
278 static public function convert($string, $from, $to='')
\r
282 $to = self::$current_charset;
\r
285 if ( $from == $to )
\r
289 else if ( self::$mode == 'iconv' )
\r
291 $string = iconv($from, $to.'//TRANSLIT', $string);
\r
293 else if ( self::$mode == 'mbstring' )
\r
295 $string = mb_convert_encoding($string, $to, $from);
\r
297 return (string) $string;
\r
301 * i18n::convert_handler
\r
302 * callable handler for character set converter
\r
305 * @param string $string target string binary
\r
308 static public function convert_handler($string)
\r
310 return self::convert($string, self::$current_charset, self::$forced_charset);
\r
314 * i18n::convert_array
\r
315 * recursively converting array
\r
318 * @param array $array array to convert
\r
321 static public function convert_array($array, $from, $to='')
\r
323 if ( !is_array($array) )
\r
325 $array = self::convert($array, $from, $to);
\r
329 foreach ( $array as $key => $value )
\r
331 if ( !is_array($value) )
\r
333 $array[$key] = self::convert($value, $from, $to);
\r
337 self::convert_array($array[$key]);
\r
350 * @param string $string target string
\r
351 * @return integer the number of letters
\r
353 static public function strlen($string)
\r
356 if ( self::$mode == 'iconv' )
\r
358 $length = iconv_strlen($string, self::$current_charset);
\r
360 else if ( self::$mode == 'mbstring' )
\r
362 $length = mb_strlen($string, self::$current_charset);
\r
366 $length = strlen($string);
\r
368 return (integer) $length;
\r
376 * @param string $haystack string to search
\r
377 * @param string $needle string for search
\r
378 * @param integer $offset the position from which the search should be performed.
\r
379 * @return integer/FALSE the numeric position of the first occurrence of needle in haystack
\r
381 static public function strpos($haystack, $needle, $offset=0)
\r
384 if ( self::$mode == 'iconv' )
\r
386 $position = iconv_strpos($haystack, $needle, $offset, self::$current_charset);
\r
388 else if ( self::$mode == 'mbstring' )
\r
390 $position = mb_strpos($haystack, $needle, $offset, self::$current_charset);
\r
394 $position = strpos($haystack, $needle, $offset);
\r
397 if ( $position !== FALSE)
\r
399 $position = (integer) $position;
\r
409 * @param string $haystack string to search
\r
410 * @param string $needle string for search
\r
411 * @return integer/FALSE the numeric position of the last occurrence of needle in haystack
\r
413 static public function strrpos ($haystack, $needle)
\r
416 if ( self::$mode == 'iconv' )
\r
418 $position = iconv_strrpos($haystack, $needle, self::$current_charset);
\r
420 else if ( self::$mode == 'mbstring' )
\r
422 $position = mb_strrpos($haystack, $needle, 0, self::$current_charset);
\r
426 $position = strrpos($haystack, $needle, 0);
\r
429 if ( $position !== FALSE)
\r
431 $position = (integer) $position;
\r
441 * @param string $string string to be cut
\r
442 * @param string $start the position of starting
\r
443 * @param integer $length the length to be cut
\r
444 * @return string the extracted part of string
\r
446 static public function substr($string, $start, $length=0)
\r
450 if ( $length == 0 )
\r
452 $length = self::strlen($string) - $start;
\r
455 if ( self::$mode == 'iconv' )
\r
457 $return = iconv_substr($string, $start, $length, self::$current_charset);
\r
459 else if ( self::$mode == 'mbstring' )
\r
461 $return = mb_substr($string, $start, $length, self::$current_charset);
\r
465 $return = strrpos($string, $start, $length);
\r
467 return (string) $return;
\r
472 * strftime function based on multibyte processing
\r
475 * @param string $format format with singlebyte or multibyte
\r
476 * @param timestamp $timestamp UNIX timestamp
\r
477 * @return string formatted timestamp
\r
479 static public function strftime($format, $timestamp='')
\r
481 return preg_replace_callback('/(%[a-z%])/i',
\r
482 create_function('$matches', 'return strftime($matches[1], ' . intval($timestamp) . ');'),
\r
488 * i18n::formatted_datetime()
\r
489 * return formatted datetime string
\r
491 * Date and Time Formats
\r
492 * @link http://www.w3.org/TR/NOTE-datetime
\r
494 * Working with Time Zones
\r
495 * @link http://www.w3.org/TR/timezone/
\r
497 * @param String $format time expression format
\r
498 * @param String $timestamp UNIX timestamp
\r
499 * @param Integer $offset timestamp offset
\r
500 * @return String formatted datetime
\r
502 static public function formatted_datetime($format, $timestamp, $offset=0)
\r
511 * MySQL 5.0 Reference Manual
\r
512 * 10.3.1. The DATE, DATETIME, and TIMESTAMP Types
\r
513 * http://dev.mysql.com/doc/refman/5.0/en/datetime.html
\r
515 $timestamp += $offset;
\r
516 $format = '%Y-%m-%d %H:%M:%S';
\r
521 * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
\r
522 * 5. DATE AND TIME SPECIFICATION
\r
523 * http://www.ietf.org/rfc/rfc0822.txt
\r
525 $format = '%a, %d %m %y %H:%M:%S ';
\r
529 $offset = -$offset;
\r
536 $suffix .= sprintf("%02d%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
\r
540 * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
\r
541 * 5. DATE AND TIME SPECIFICATION
\r
542 * http://www.ietf.org/rfc/rfc0822.txt
\r
544 $format = '%a, %d %m %y %H:%M:%S ';
\r
545 $timestamp -= $offset;
\r
551 * RFC3339: Date and Time on the Internet: Timestamps
\r
552 * 5. Date and Time format
\r
553 * http://www.ietf.org/rfc/rfc3339.txt
\r
555 $format = '%Y-%m-%dT%H:%M:%S';
\r
559 $offset = -$offset;
\r
565 $suffix .= sprintf("%02d:%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
\r
571 * RFC3339: Date and Time on the Internet: Timestamps
\r
572 * 5. Date and Time format
\r
573 * http://www.ietf.org/rfc/rfc3339.txt
\r
575 $timestamp -= $offset;
\r
576 $format = '%Y-%m-%dT%H:%M:%SZ';
\r
587 return i18n::strftime($format, $timestamp) . $suffix;
\r
591 * i18n::convert_locale_to_old_language_file_name()
\r
592 * NOTE: this should be obsoleted near future.
\r
595 * @param string $target_locale locale name as language_script_region
\r
596 * @return string old translation file name
\r
598 static public function convert_locale_to_old_language_file_name($target_locale)
\r
600 $target_language = '';
\r
601 foreach ( self::$lang_refs as $language => $locale )
\r
603 if ( preg_match('#-#', $language) )
\r
605 if ( $target_locale . '.' . self::$current_charset == $locale )
\r
607 $target_language = $language;
\r
611 else if ( $target_locale == $locale )
\r
613 $target_language = $language;
\r
616 return $target_language;
\r
620 * i18n::convert_old_language_file_name_to_locale()
\r
621 * NOTE: this should be obsoleted near future.
\r
624 * @param string $target_language old translation file name
\r
625 * @return string locale name as language_script_region
\r
627 static public function convert_old_language_file_name_to_locale($target_language)
\r
629 $target_locale = '';
\r
630 foreach ( self::$lang_refs as $language => $locale )
\r
632 if ( $target_language == $language )
\r
634 if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) )
\r
636 $target_locale = $match[1];
\r
640 $target_locale = $locale;
\r
645 return $target_locale;
\r
650 * reference table to convert old and new way to name translation files.
\r
651 * NOTE: this should be obsoleted as soon as possible.
\r
655 static private $lang_refs = array(
\r
656 "english" => "en_Latn_US",
\r
657 "english-utf8" => "en_Latn_US.UTF-8",
\r
658 "bulgarian" => "bg_Cyrl_BG",
\r
659 "finnish" => "fi_Latn_FU",
\r
660 "catalan" => "ca_Latn_ES",
\r
661 "french" => "fr_Latn_FR",
\r
662 "russian" => "ru_Cyrl_RU",
\r
663 "chinese" => "zh_Hans_CN",
\r
664 "simchinese" => "zh_Hans_CN",
\r
665 "chineseb5" => "zh_Hant_TW",
\r
666 "traditional_chinese" => "zh_Hant_TW",
\r
667 "galego" => "gl_Latn_ES",
\r
668 "german" => "de_Latn_DE",
\r
669 "korean-utf" => "ko_Kore_KR.UTF-8",
\r
670 "korean-euc-kr" => "ko_Kore_KR.EUC-KR",
\r
671 "slovak" => "sk_Latn_SK",
\r
672 "czech" => "cs_Latn_CZ",
\r
673 "hungarian" => "hu_Latn_HU",
\r
674 "latvian" => "lv_Latn_LV",
\r
675 "nederlands" => "nl_Latn_NL",
\r
676 "italiano" => "it_Latn_IT",
\r
677 "persian" => "fa_Arab_IR",
\r
678 "spanish" => "es_Latn_ES",
\r
679 "spanish-utf8" => "es_Latn_ES.UTF-8",
\r
680 "japanese-euc" => "ja_Jpan_JP.EUC-JP",
\r
681 "japanese-utf8" => "ja_Jpan_JP.UTF-8",
\r
682 "portuguese_brazil" => "pt_Latn_BR"
\r
688 * i18n class for Nucleus CMS
689 * written by Takashi Sakamoto as of Feb 03, 2012
691 * This includes wrapper functions of iconv and mbstring
692 * for multibyte processing and includes parameters related to locale.
694 * This program is free software; you can redistribute it and/or
695 * modify it under the terms of the GNU General Public License
696 * as published by the Free Software Foundation; either version 2
697 * of the License, or (at your option) any later version.
698 * (see nucleus/documentation/index.html#license for more info)
700 * @license http://nucleuscms.org/license.txt GNU General Public License
701 * @copyright Copyright (C) 2002-2011 The Nucleus Group
702 * @version $Id: i18n.php 1876 2012-06-17 07:33:00Z sakamocchi $
706 static private $mode = FALSE;
708 static private $current_charset = '';
709 static private $current_language = '';
710 static private $current_script = '';
711 static private $current_region = '';
713 static private $locale_list = array();
714 static private $timezone = 'UTC';
716 static private $forced_charset = '';
717 static private $forced_language = '';
718 static private $forced_script = '';
719 static private $forced_region = '';
723 * Initializing i18n class
726 * @param string $charset character set
729 static public function init($charset, $dir)
731 /* i18n is already initialized */
737 /* make locale list in this Nucleus CMS */
738 if ( ($handle = opendir($dir)) === FALSE )
742 while ($filename = readdir($handle))
744 if (preg_match("#^(.+_.+_.+)\.{$charset}\.php$#", $filename, $matches) )
746 if ( !in_array($matches[1], self::$locale_list) )
748 self::$locale_list[] = $matches[1];
754 /* set i18n backend and validate character set */
755 if ( extension_loaded('iconv') )
757 /* this is just for checking the charset. */
758 if ( iconv_set_encoding('internal_encoding', $charset)
759 && iconv_set_encoding('output_encoding', $charset)
760 && iconv_set_encoding('internal_encoding', $charset) )
762 self::$current_charset = $charset;
763 self::$mode = 'iconv';
766 else if ( extension_loaded('mbstring') )
768 /* this is just for checking the charset. */
769 if ( mb_http_output($charset)
770 && mb_internal_encoding($charset)
771 && mb_regex_encoding($charset) )
773 self::$current_charset = $charset;
774 self::$mode = 'mbstring';
782 * i18n::get_available_locale_list
783 * return available locale list with current charset
787 * @return array available locale list
789 static public function get_available_locale_list()
791 return self::$locale_list;
795 * i18n::get_current_charset
796 * return current charset
800 * @return string $charset current character set
802 static public function get_current_charset()
804 return self::$current_charset;
812 * naming rule is "$language_$script_$region.$charset.php", refer to RFC 5646.
813 * @link http://www.ietf.org/rfc/rfc5646.txt
814 * @see 2. The Language Tag
817 * @param string $locale
818 * @return bool TRUE/FALSE
821 static public function set_current_locale($locale)
823 if ( preg_match('#^(.+)_(.+)_(.+)$#', $locale, $match) )
825 self::$current_language = $match[1];
826 self::$current_script = $match[2];
827 self::$current_region = $match[3];
841 static public function get_current_locale()
843 $elements = array(self::$current_language, self::$current_script, self::$current_region);
844 return implode('_', $elements);
848 * i18n::set_forced_locale()
852 * @param string $forced_locale
853 * @return bool TRUE/FALSE
856 static public function set_forced_locale($forced_locale)
858 if ( preg_match('#^(.+)_(.+)_(.+)$#', $forced_locale, $match) )
860 self::$forced_language = $match[1];
861 self::$forced_script = $match[2];
862 self::$forced_region = $match[3];
869 * i18n::get_forced_locale
874 * @return $forced_locale
876 static public function get_forced_locale()
878 if ( !self::$forced_language )
883 $elements = array(self::$forced_language, self::$forced_script, self::$forced_region);
884 return implode('_', $elements);
888 * i18n::set_forced_charset
889 * return forced charset
892 * @param void $charset forced character set
895 static public function set_forced_charset($forced_charset)
897 self::$forced_charset = $forced_charset;
902 * i18n::get_forced_charset
903 * return forced charset
907 * @return string $charset forced character set
909 static public function get_forced_charset()
911 return self::$forced_charset;
915 * i18n::confirm_default_date_timezone
916 * to avoid E_NOTICE or E_WARNING generated when every calling to a date/time function.
919 * Some private servers are lack of its timezone setting
920 * http://www.php.net/manual/en/function.date-default-timezone-set.php
926 static public function confirm_default_date_timezone()
928 if ( function_exists('date_default_timezone_get')
929 && FALSE !== ($timezone = @date_default_timezone_get()))
931 self::$timezone = $timezone;
933 if (function_exists('date_default_timezone_set')) {
934 @date_default_timezone_set(self::$timezone);
940 * i18n::get_current_date_timezone()
941 * get current timezone
947 static public function get_date_timezone()
949 return self::$timezone;
954 * character set converter
957 * @param string $string target string binary
958 * @param string $from original character set encoding
959 * @param string $to target character set encoding
960 * @return string converted string
962 static public function convert($string, $from, $to='')
966 $to = self::$current_charset;
973 else if ( self::$mode == 'iconv' )
975 $string = iconv($from, $to.'//TRANSLIT', $string);
977 else if ( self::$mode == 'mbstring' )
979 $string = mb_convert_encoding($string, $to, $from);
981 return (string) $string;
985 * i18n::convert_handler
986 * callable handler for character set converter
989 * @param string $string target string binary
992 static public function convert_handler($string)
994 return self::convert($string, self::$current_charset, self::$forced_charset);
998 * i18n::convert_array
999 * recursively converting array
1002 * @param array $array array to convert
1005 static public function convert_array($array, $from, $to='')
1007 if ( !is_array($array) )
1009 $array = self::convert($array, $from, $to);
1013 foreach ( $array as $key => $value )
1015 if ( !is_array($value) )
1017 $array[$key] = self::convert($value, $from, $to);
1021 self::convert_array($array[$key]);
1034 * @param string $string target string
1035 * @return integer the number of letters
1037 static public function strlen($string)
1040 if ( self::$mode == 'iconv' )
1042 $length = iconv_strlen($string, self::$current_charset);
1044 else if ( self::$mode == 'mbstring' )
1046 $length = mb_strlen($string, self::$current_charset);
1050 $length = strlen($string);
1052 return (integer) $length;
1060 * @param string $haystack string to search
1061 * @param string $needle string for search
1062 * @param integer $offset the position from which the search should be performed.
1063 * @return integer/FALSE the numeric position of the first occurrence of needle in haystack
1065 static public function strpos($haystack, $needle, $offset=0)
1068 if ( self::$mode == 'iconv' )
1070 $position = iconv_strpos($haystack, $needle, $offset, self::$current_charset);
1072 else if ( self::$mode == 'mbstring' )
1074 $position = mb_strpos($haystack, $needle, $offset, self::$current_charset);
1078 $position = strpos($haystack, $needle, $offset);
1081 if ( $position !== FALSE)
1083 $position = (integer) $position;
1093 * @param string $haystack string to search
1094 * @param string $needle string for search
1095 * @return integer/FALSE the numeric position of the last occurrence of needle in haystack
1097 static public function strrpos ($haystack, $needle)
1100 if ( self::$mode == 'iconv' )
1102 $position = iconv_strrpos($haystack, $needle, self::$current_charset);
1104 else if ( self::$mode == 'mbstring' )
1106 $position = mb_strrpos($haystack, $needle, 0, self::$current_charset);
1110 $position = strrpos($haystack, $needle, 0);
1113 if ( $position !== FALSE)
1115 $position = (integer) $position;
1125 * @param string $string string to be cut
1126 * @param string $start the position of starting
1127 * @param integer $length the length to be cut
1128 * @return string the extracted part of string
1130 static public function substr($string, $start, $length=0)
1136 $length = self::strlen($string) - $start;
1139 if ( self::$mode == 'iconv' )
1141 $return = iconv_substr($string, $start, $length, self::$current_charset);
1143 else if ( self::$mode == 'mbstring' )
1145 $return = mb_substr($string, $start, $length, self::$current_charset);
1149 $return = strrpos($string, $start, $length);
1151 return (string) $return;
1156 * strftime function based on multibyte processing
1159 * @param string $format format with singlebyte or multibyte
1160 * @param timestamp $timestamp UNIX timestamp
1161 * @return string formatted timestamp
1163 static public function strftime($format, $timestamp='')
1165 return preg_replace_callback('/(%[a-z%])/i',
1166 create_function('$matches', 'return strftime($matches[1], ' . intval($timestamp) . ');'),
1172 * i18n::formatted_datetime()
1173 * return formatted datetime string
1175 * Date and Time Formats
1176 * @link http://www.w3.org/TR/NOTE-datetime
1178 * Working with Time Zones
1179 * @link http://www.w3.org/TR/timezone/
1181 * @param String $format time expression format
1182 * @param String $timestamp UNIX timestamp
1183 * @param Integer $offset timestamp offset
1184 * @return String formatted datetime
1186 static public function formatted_datetime($format, $timestamp, $offset=0)
1195 * MySQL 5.0 Reference Manual
1196 * 10.3.1. The DATE, DATETIME, and TIMESTAMP Types
1197 * http://dev.mysql.com/doc/refman/5.0/en/datetime.html
1199 $timestamp += $offset;
1200 $format = '%Y-%m-%d %H:%M:%S';
1206 * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
1207 * 5. DATE AND TIME SPECIFICATION
1208 * http://www.ietf.org/rfc/rfc0822.txt
1210 $format = '%a, %d %m %y %H:%M:%S ';
1221 $suffix .= sprintf("%02d%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
1225 * RFC 822: STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES
1226 * 5. DATE AND TIME SPECIFICATION
1227 * http://www.ietf.org/rfc/rfc0822.txt
1229 $format = '%a, %d %m %y %H:%M:%S ';
1230 $timestamp -= $offset;
1236 * RFC3339: Date and Time on the Internet: Timestamps
1237 * 5. Date and Time format
1238 * http://www.ietf.org/rfc/rfc3339.txt
1240 $format = '%Y-%m-%dT%H:%M:%S';
1250 $suffix .= sprintf("%02d:%02d", floor($offset / 3600), round(($offset % 3600) / 60) );
1256 * RFC3339: Date and Time on the Internet: Timestamps
1257 * 5. Date and Time format
1258 * http://www.ietf.org/rfc/rfc3339.txt
1260 $timestamp -= $offset;
1261 $format = '%Y-%m-%dT%H:%M:%SZ';
1272 return i18n::strftime($format, $timestamp) . $suffix;
1276 * i18n::convert_locale_to_old_language_file_name()
1277 * NOTE: this should be obsoleted near future.
1280 * @param string $target_locale locale name as language_script_region
1281 * @return string old translation file name
1283 static public function convert_locale_to_old_language_file_name($target_locale)
1285 $target_language = '';
1286 foreach ( self::$lang_refs as $language => $locale )
1288 if ( preg_match('#-#', $language) )
1290 if ( $target_locale . '.' . self::$current_charset == $locale )
1292 $target_language = $language;
1296 else if ( $target_locale == $locale )
1298 $target_language = $language;
1301 return $target_language;
1305 * i18n::convert_old_language_file_name_to_locale()
1306 * NOTE: this should be obsoleted near future.
1309 * @param string $target_language old translation file name
1310 * @return string locale name as language_script_region
1312 static public function convert_old_language_file_name_to_locale($target_language)
1314 $target_locale = '';
1315 foreach ( self::$lang_refs as $language => $locale )
1317 if ( $target_language == $language )
1319 if ( preg_match('#^(.+)\.(.+)$#', $locale, $match) )
1321 $target_locale = $match[1];
1325 $target_locale = $locale;
1330 return $target_locale;
1335 * reference table to convert old and new way to name translation files.
1336 * NOTE: this should be obsoleted as soon as possible.
1340 static private $lang_refs = array(
1341 "english" => "en_Latn_US",
1342 "english-utf8" => "en_Latn_US.UTF-8",
1343 "bulgarian" => "bg_Cyrl_BG",
1344 "finnish" => "fi_Latn_FI",
1345 "catalan" => "ca_Latn_ES",
1346 "french" => "fr_Latn_FR",
1347 "russian" => "ru_Cyrl_RU",
1348 "chinese" => "zh_Hans_CN",
1349 "simchinese" => "zh_Hans_CN",
1350 "chineseb5" => "zh_Hant_TW",
1351 "traditional_chinese" => "zh_Hant_TW",
1352 "galego" => "gl_Latn_ES",
1353 "german" => "de_Latn_DE",
1354 "korean-utf" => "ko_Kore_KR.UTF-8",
1355 "korean-euc-kr" => "ko_Kore_KR.EUC-KR",
1356 "slovak" => "sk_Latn_SK",
1357 "czech" => "cs_Latn_CZ",
1358 "hungarian" => "hu_Latn_HU",
1359 "latvian" => "lv_Latn_LV",
1360 "nederlands" => "nl_Latn_NL",
1361 "italiano" => "it_Latn_IT",
1362 "persian" => "fa_Arab_IR",
1363 "spanish" => "es_Latn_ES",
1364 "spanish-utf8" => "es_Latn_ES.UTF-8",
1365 "japanese-euc" => "ja_Jpan_JP.EUC-JP",
1366 "japanese-utf8" => "ja_Jpan_JP.UTF-8",
1367 "portuguese_brazil" => "pt_Latn_BR"
1370 >>>>>>> skinnable-master