/var/Typecho/I18n.php
PHP | 203 lines | 84 code | 19 blank | 100 comment | 32 complexity | 416bdf8cd9b23cade0dbf83cc2aa54e2 MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- /**
- * Typecho Blog Platform
- *
- * @copyright Copyright (c) 2008 Typecho team (http://www.typecho.org)
- * @license GNU General Public License 2.0
- * @version $Id: I18n.php 106 2008-04-11 02:23:54Z magike.net $
- */
- /**
- * I18n function
- *
- * @param string $string ???????
- * @return string
- */
- function _t($string)
- {
- if (func_num_args() <= 1) {
- return Typecho_I18n::translate($string);
- } else {
- $args = func_get_args();
- array_shift($args);
- return vsprintf(Typecho_I18n::translate($string), $args);
- }
- }
- /**
- * I18n function, translate and echo
- *
- * @param string $string ??????????
- * @return void
- */
- function _e()
- {
- $args = func_get_args();
- echo call_user_func_array('_t', $args);
- }
- /**
- * ???????????
- *
- * @param string $single ???????
- * @param string $plural ???????
- * @param integer $number ??
- * @return string
- */
- function _n($single, $plural, $number)
- {
- return Typecho_I18n::ngettext($single, $plural, $number);
- }
- /**
- * ???????
- *
- * @package I18n
- */
- class Typecho_I18n
- {
- /**
- * ??????????
- *
- * @access private
- * @var boolean
- */
- private static $_loaded = false;
- /**
- * ????
- *
- * @access private
- * @var string
- */
- private static $_lang = NULL;
- /**
- * ???????
- *
- * @access private
- * @return boolean
- */
- private static function init()
- {
- /** GetText?? */
- require_once 'Typecho/I18n/GetTextMulti.php';
- self::$_loaded = new Typecho_I18n_GetTextMulti(self::$_lang);
- return true;
- }
- /**
- * ????
- *
- * @access public
- * @param string $string ??????
- * @return string
- */
- public static function translate($string)
- {
- self::$_lang && empty(self::$_loaded) && self::init();
- return self::$_lang ? self::$_loaded->translate($string) : $string;
- }
- /**
- * ???????????
- *
- * @param string $single ???????
- * @param string $plural ???????
- * @param integer $number ??
- * @return string
- */
- public static function ngettext($single, $plural, $number)
- {
- self::$_lang && empty(self::$_loaded) && self::init();
- return self::$_lang ? self::$_loaded->ngettext($single, $plural, $number) : ($number > 1 ? $plural : $single);
- }
- /**
- * ?????
- *
- * @access public
- * @param string $from ????
- * @param string $now ????
- * @return string
- */
- public static function dateWord($from, $now)
- {
- $between = $now - $from;
- /** ????? */
- if ($between > 0 && $between < 86400 && idate('d', $from) == idate('d', $now)) {
- /** ?????? */
- if ($between < 3600 && idate('H', $from) == idate('H', $now)) {
- /** ?????? */
- if ($between < 60 && idate('i', $from) == idate('i', $now)) {
- $second = idate('s', $now) - idate('s', $from);
- if (0 == $second) {
- return _t('??');
- } else {
- return sprintf(_n('%d??', '%d??', $second), $second);
- }
- }
- $min = idate('i', $now) - idate('i', $from);
- return sprintf(_n('%d???', '%d???', $min), $min);
- }
- $hour = idate('H', $now) - idate('H', $from);
- return sprintf(_n('%d???', '%d???', $hour), $hour);
- }
- /** ????? */
- if ($between > 0 && $between < 172800 && (idate('z', $from) + 1 == idate('z', $now) || idate('z', $from) > 2 + idate('z', $now))) {
- return _t('?? %s', date('H:i', $from));
- }
- /** ??????? */
- if ($between > 0 && $between < 604800 && idate('W', $from) == idate('W', $now)) {
- $day = intval($between / (3600 * 24));
- return sprintf(_n('%d??', '%d??', $day), $day);
- }
- /** ??? */
- if ($between > 0 && $between < 31622400 && idate('Y', $from) == idate('Y', $now)) {
- return date(_t('n?j?'), $from);
- }
- return date(_t('Y?m?d?'), $from);
- }
- /**
- * ?????
- *
- * @access public
- * @param string $lang ????
- * @return void
- */
- public static function setLang($lang)
- {
- self::$_lang = $lang;
- }
- /**
- * ?????
- *
- * @access public
- * @param string $lang ????
- * @return void
- */
- public static function addLang($lang)
- {
- self::$_loaded->addFile($lang);
- }
- /**
- * ?????
- *
- * @access public
- * @return void
- */
- public static function getLang()
- {
- return self::$_lang;
- }
- }