Kdyby\Translation\Translator::translate PHP Method

translate() public method

Translates the given string.
public translate ( string $message, integer $count = NULL, array $parameters = [], string $domain = NULL, string $locale = NULL ) : string
$message string The message id
$count integer The number to use to find the indice of the message
$parameters array An array of parameters for the message
$domain string The domain for the message
$locale string The locale
return string
    public function translate($message, $count = NULL, $parameters = [], $domain = NULL, $locale = NULL)
    {
        if ($message instanceof Phrase) {
            return $message->translate($this);
        }
        if (is_array($count)) {
            $locale = $domain ?: NULL;
            $domain = $parameters ?: NULL;
            $parameters = $count;
            $count = NULL;
        }
        if (empty($message)) {
            return $message;
        } elseif ($message instanceof Nette\Utils\Html) {
            if ($this->panel) {
                $this->panel->markUntranslated($message, $domain);
            }
            return $message;
            // todo: what now?
        }
        $tmp = [];
        foreach ($parameters as $key => $val) {
            $tmp['%' . trim($key, '%') . '%'] = $val;
        }
        $parameters = $tmp;
        if ($count !== NULL && is_scalar($count)) {
            return $this->transChoice($message, $count, $parameters + ['%count%' => $count], $domain, $locale);
        }
        return $this->trans($message, $parameters, $domain, $locale);
    }

Usage Example

 /**
  * @param \Nette\Forms\Container $container
  * @param ConstraintViolationList|ConstraintViolationInterface[] $violations
  */
 public function mapViolationsToForm(Container $container, ConstraintViolationList $violations)
 {
     foreach ($violations as $violation) {
         $control = $this->findControl($container, $violation);
         $control->addError($this->translator->translate($violation->getMessageTemplate(), $violation->getMessagePluralization(), $violation->getMessageParameters(), 'validators'));
     }
 }
All Usage Examples Of Kdyby\Translation\Translator::translate