Example #1
0
 /**
  * Calculate age for given timestamp(s)
  *
  * @param  mixed $timestamp1  accepts string, unix-timestamp and DateTime object
  * @param  mixed $timestamp2  accepts string, unix-timestamp and DateTime object
  * @param  string $unit       constraint output to a given unit
  * @return string
  */
 public function age($timestamp1, $timestamp2 = null, $unit = null)
 {
     $timestamp1 = is_numeric($timestamp1) ? '@' . intval($timestamp1) : $timestamp1;
     $timestamp1 = is_a($timestamp1, 'DateTime') ? $timestamp1 : new DateTime($timestamp1);
     $timestamp2 = is_numeric($timestamp2) ? '@' . intval($timestamp2) : $timestamp2;
     $timestamp2 = is_a($timestamp2, 'DateTime') ? $timestamp2 : new DateTime($timestamp2);
     if ($timestamp1 == $timestamp2) {
         return $this->translator->get($this->getTranslationKey('date.n0w'));
     }
     $diff = $timestamp1->diff($timestamp2);
     $total = array('year' => $diff->y, 'month' => $diff->m + $diff->y * 12, 'week' => floor($diff->days / 7), 'day' => $diff->days, 'hour' => $diff->h + $diff->days * 24, 'minute' => $diff->h + $diff->i + $diff->days * 24 * 60, 'second' => $diff->h + $diff->i + $diff->s + $diff->days * 24 * 60 * 60);
     if (is_null($unit)) {
         foreach ($total as $key => $value) {
             if ($value > 0) {
                 $lang_key = 'date.' . $key . '_choice';
                 $lang_key = $this->getTranslationKey($lang_key);
                 $unit = $this->translator->choice($lang_key, $value);
                 return $value . ' ' . $unit;
             }
         }
     } elseif (array_key_exists($unit, $total)) {
         $value = $total[$unit];
         $lang_key = 'date.' . $unit . '_choice';
         $lang_key = $this->getTranslationKey($lang_key);
         $unit = $this->translator->choice($lang_key, $value);
         return $value . ' ' . $unit;
     }
     throw new \InvalidArgumentException('Invalid argument in function call');
 }
Example #2
0
 /**
  * Get a translation according to an integer value.
  *
  * @param  string  $key
  * @param  int     $number
  * @param  array   $replace
  * @param  string  $locale
  * @param  bool    $wrap
  *
  * @return string
  */
 public function choice($key, $number, array $replace = array(), $locale = null, $wrap = true)
 {
     if (!Lari18n::isActivated()) {
         return parent::choice($key, $number, $replace, $locale);
     }
     $line = $this->get($key, $replace, $locale = $locale ?: $this->locale, false);
     $replace['count'] = $number;
     $hasTodo = strpos($line, $this->lari18n->todo_translation_key) > -1;
     $chosen = $this->makeReplacements($this->getSelector()->choose($line, $number, $locale), $replace);
     // Reapply the todo_translation_key if needed
     $chosen = $hasTodo ? $this->lari18n->todo_translation_key . $chosen : $chosen;
     if ($wrap == false) {
         return $chosen;
     } else {
         return $this->lari18n->wrap($chosen, $key, $replace, $locale, $number, $wrap);
     }
 }
Example #3
0
 /**
  * Get a translation according to an integer value.
  *
  * @param string $key
  * @param int $number
  * @param array $replace
  * @param string $locale
  * @return string 
  * @static 
  */
 public static function choice($key, $number, $replace = array(), $locale = null)
 {
     return \Illuminate\Translation\Translator::choice($key, $number, $replace, $locale);
 }
 /**
  * Get a translation according to an integer value.
  *
  * @param  string $key
  * @param  int    $number
  * @param  array  $replace
  * @param  string $locale
  *
  * @return string
  */
 public function choice($key, $number, array $replace = array(), $locale = null, $useDB = null)
 {
     if (!$this->suspendInPlaceEdit && $this->inPlaceEditing()) {
         return $this->get($key, $replace, $locale, $useDB);
     } else {
         if ($useDB !== null) {
             $oldUseDB = $this->useDB;
             $this->useDB = $useDB;
             $retVal = parent::choice($key, $number, $replace, $locale);
             $this->useDB = $oldUseDB;
             return $retVal;
         } else {
             return parent::choice($key, $number, $replace, $locale);
         }
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  *
  * @param  string  $key
  * @param  int     $number
  * @param  array   $replace
  * @param  string  $locale
  * @return string
  */
 public function choice($key, $number, array $replace = array(), $locale = null)
 {
     return $this->lang->choice($key, $number, $replace, $locale);
 }
Example #6
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $keep = (int) $this->argument('keep');
     $removedBackups = count($this->cleaner->removeOldBackups($keep));
     $this->info($this->translator->choice('backups.cleaned', $removedBackups, ['amount' => $removedBackups]));
 }
 /**
  * Get a translation according to an integer value.
  *
  * @param  string $key
  * @param  int    $number
  * @param  array  $replace
  * @param  string $locale
  *
  * @return string
  */
 public function choice($key, $number, array $replace = array(), $locale = null, $useDB = null)
 {
     $inplaceEditMode = $this->manager->config('inplace_edit_mode');
     if ($this->inPlaceEditing() && $inplaceEditMode == 2) {
         if (!in_array($key, $this->usedKeys)) {
             $this->usedKeys[] = $key;
         }
     }
     if (!$this->suspendInPlaceEdit && $this->inPlaceEditing() && $inplaceEditMode == 1) {
         return $this->get($key, $replace, $locale, $useDB);
     } else {
         if ($useDB !== null) {
             $oldUseDB = $this->useDB;
             $this->useDB = $useDB;
             $retVal = parent::choice($key, $number, $replace, $locale);
             $this->useDB = $oldUseDB;
             return $retVal;
         } else {
             return parent::choice($key, $number, $replace, $locale);
         }
     }
 }