Exemple #1
0
 /**
  * @description Setting bad language throws exception
  */
 function setbadlanguage()
 {
     intl::setLanguage('sv');
     try {
         intl::setLanguage('swe');
     } catch (Exception $e) {
         $this->assertEquals(intl::getLanguage(), 'sv');
         return;
     }
     $this->explicitFail('No exception thrown');
 }
Exemple #2
0
 /**
  * Calculates the time past since an event occured, f.ex. "2 days ago".
  * Taken from the php.net website.
  *
  * @author andypsv <*****@*****.**>
  */
 function ago($time = null)
 {
     if ($time) {
         $d = new Timestamp($time);
         return $d->ago();
     }
     $tm = $this->_time;
     $cur_tm = time();
     $dif = $cur_tm - $tm;
     $pds = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
     $pdsp = array('seconds', 'minutes', 'hours', 'days', 'weeks', 'months', 'years', 'decades');
     if (modulemanager::has('i18n')) {
         foreach ($pds as &$pd) {
             $pd = intl::str($pd);
         }
         foreach ($pdsp as &$pd) {
             $pd = intl::str($pd);
         }
     }
     $lngh = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
     for ($v = sizeof($lngh) - 1; $v >= 0 && ($no = $dif / $lngh[$v]) <= 1; $v--) {
     }
     if ($v < 0) {
         $v = 0;
     }
     $_tm = $cur_tm - $dif % $lngh[$v];
     $no = floor($no);
     if ($no != 1) {
         $pds[$v] = $pdsp[$v];
     }
     $x = sprintf("%d %s ", $no, $pds[$v]);
     // if(($rcs == 1)&&($v >= 1)&&(($cur_tm-$_tm) > 0)) $x .= time_ago($_tm);
     return $x;
 }
Exemple #3
0
 /**
  * @brief Set the default language
  *
  *
  */
 static function setLanguage($lang)
 {
     if (preg_match('/^[a-z]{2}$/', $lang)) {
         // Two letter iso code found
         self::$lang = $lang;
         self::$region = null;
     } elseif (preg_match('/^[a-z]{2}-[a-z]{2}$/', $lang)) {
         // Two letter iso country and two letter iso code
         list(self::$lang, self::$region) = explode('-', $lang);
     } elseif ($lang == null) {
         self::$lang = null;
         self::$region = null;
     } else {
         throw new BaseException("Invalid language");
     }
 }