コード例 #1
0
 /**
  * Returns current user's locale.
  *
  * @return  string  E.g., 'en_US'.
  */
 public function getLocale()
 {
     if ($locale = waLocale::getLocale()) {
         return $locale;
     }
     return $this->getUser()->getLocale();
 }
コード例 #2
0
 private static function __w($string, $type, $id, $path)
 {
     static $domains = array();
     $domain = sprintf('%s_%s', $type, $id);
     if (!isset($domains[$domain])) {
         $locale_path = $path . '/locale';
         if ($domains[$domain] = file_exists($locale_path)) {
             waLocale::load(waLocale::getLocale(), $locale_path, $domain, false);
         }
     }
     $args = (array) $string;
     if ($domains[$domain]) {
         array_unshift($args, $domain);
         $string = call_user_func_array('_wd', $args);
     } else {
         $string = reset($args);
     }
     return $string;
 }
コード例 #3
0
ファイル: waDateTime.class.php プロジェクト: Lazary/webasyst
 /**
  * Returns time as string according to specified format.
  *
  * @see wa_date()
  *
  * @param string $format Date/time format. The following format strings are acceptable:
  *     - 'humandatetime': adds words "yesterday", "today", "tomorrow" instead of appropriate dates relative to the
  *       current user date
  *     - 'humandate': returns the date in format 'd f Y' supported by method date (format strings listed below are
  *       also supported by that method)
  *     - 'date': returns date/time in format 'Y-m-d'
  *     - 'time': returns date/time in format 'H:i'
  *     - 'fulltime': returns date/time in format 'H:i:s'
  *     - 'datetime': returns date/time in format 'Y-m-d H:i'
  *     - 'fulldatetime': returns date/time in format 'Y-m-d H:i:s'
  *     - 'timestamp': returns date/time in format 'U'
  * @param string|null $time Unix timestamp. If not specified, current timestamp is used.
  * @param string|null $timezone Time zone identifier. If not specified, the time zone is determined automatically.
  * @param string|null $locale Locale identifier. If not specifed, current user's locale is determined automatically.
  * @return string
  */
 public static function format($format, $time = null, $timezone = null, $locale = null)
 {
     if (!$locale) {
         $locale = wa()->getLocale();
     }
     if (!$timezone) {
         $timezone = wa()->getUser()->getTimezone();
     }
     waLocale::loadByDomain("webasyst", $locale);
     $old_locale = waLocale::getLocale();
     if ($locale != $old_locale) {
         wa()->setLocale($locale);
     }
     if ($format === 'humandatetime') {
         if (preg_match("/^[0-9]+\$/", $time)) {
             $time = date("Y-m-d H:i:s", $time);
         }
         $date_time = new DateTime($time);
         $base_date_time = new DateTime(date("Y-m-d H:i:s", strtotime('-1 day')));
         if ($timezone) {
             $date_timezone = new DateTimeZone($timezone);
             $date_time->setTimezone($date_timezone);
             $base_date_time->setTimezone($date_timezone);
         }
         $day = $date_time->format('Y z');
         if ($base_date_time->format('Y z') === $day) {
             $result = _ws('Yesterday');
         } else {
             $base_date_time->modify('+1 day');
             if ($base_date_time->format('Y z') === $day) {
                 $result = _ws('Today');
             } else {
                 $base_date_time->modify('+1 day');
                 if ($base_date_time->format('Y z') === $day) {
                     $result = _ws('Tomorrow');
                 } else {
                     $result = self::date(self::getFormat('humandate', $locale), $time, $timezone, $locale);
                 }
             }
         }
         $result = $result . ' ' . self::date(self::getFormat('time', $locale), $time, $timezone, $locale);
     } else {
         $result = self::date(self::getFormat($format, $locale), $time, $timezone, $locale);
     }
     if ($locale != $old_locale) {
         wa()->setLocale($old_locale);
     }
     return $result;
 }
コード例 #4
0
 public function _w($string)
 {
     static $domains = array();
     $domain = sprintf('%s_%s', $this->type, $this->id);
     if (!isset($domains[$domain])) {
         $locale_path = $this->path . '/locale';
         if ($domains[$domain] = file_exists($locale_path)) {
             waLocale::load(waLocale::getLocale(), $locale_path, $domain, false);
         }
     }
     if ($domains[$domain]) {
         $args = func_get_args();
         array_unshift($args, $domain);
         $string = call_user_func_array('_wd', $args);
     }
     return $string;
 }