예제 #1
0
 /**
  * Translate a text.
  *
  * @param string     $text         The text to translate.
  * @param array|null $replacements Values that should be replaced.
  * @param string     $locale       The locale or null to use the current locale.
  *
  * @return string Translated text or given text if no translation found.
  */
 public function _($text, $replacements = null, $locale = null)
 {
     if (!$locale) {
         $locale = $this->getLocale();
     }
     if ($this->translator !== null) {
         $text = $this->translator->translate($text, $locale);
     }
     return $this->replace($text, $replacements);
 }
예제 #2
0
 public static function ago($time, TranslatorInterface $translator)
 {
     $lengths = array("60", "60", "24", "7", "4.35", "12", "10");
     $now = time();
     $difference = $now - $time;
     $tense = $translator->translate("ago");
     for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) {
         $difference /= $lengths[$j];
     }
     $difference = round($difference);
     $periods = array($translator->translatePlural("second", "seconds", $difference), $translator->translatePlural("minute", "minutes", $difference), $translator->translatePlural("hour", "hours", $difference), $translator->translatePlural("day", "days", $difference), $translator->translatePlural("week", "weeks", $difference), $translator->translatePlural("month", "months", $difference), $translator->translatePlural("year", "years", $difference), $translator->translatePlural("decade", "decades", $difference));
     return "{$difference} {$periods[$j]} {$tense}";
 }
 public function translate($word, $toLang, $fromLang = null)
 {
     return $this->translator->translate($word, $toLang, $fromLang);
 }