Пример #1
0
 /**
  *
  * Translates the message indicated by they key, replacing token values
  * along the way.
  *
  * @param string $key The message key.
  *
  * @param array $tokens_values Token values to interpolate into the
  * message.
  *
  * @return string The translated message with tokens replaced.
  *
  */
 public function translate($key, array $tokens_values = [])
 {
     // get the message string
     $message = $this->getMessage($key);
     // do we have a message string?
     if (!$message) {
         // no, return the message key as-is
         $message = $key;
     }
     // are there token replacement values?
     if (!$tokens_values) {
         // no, return the message string as-is
         return $message;
     }
     // run message string through formatter to replace tokens with values
     return $this->formatter->format($this->locale, $message, $tokens_values);
 }
Пример #2
0
 /**
  * @param bool $millisecondPrecision
  * @return string
  */
 public function getDurationFormatted($millisecondPrecision = true)
 {
     $duration = $this->getDuration();
     return $this->formatter->format($duration, $millisecondPrecision);
 }