Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
4 / 4
TranslatorI18NextTrait
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
2 / 2
6
100.00% covered (success)
100.00%
4 / 4
 setTranslator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 _
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
3 / 3
<?php
declare(strict_types=1);
namespace I18Next\atk4;
use atk4\core\Exception;
use I18Next\TranslatorInterface;
trait TranslatorI18NextTrait
{
    /** @var TranslatorInterface */
    protected $translator;
    /**
     * @param TranslatorInterface $translator
     *
     * @return TranslatorInterface
     */
    public function setTranslator(TranslatorInterface $translator)
    {
        return $this->translator = $translator;
    }
    /**
     * Translates the given message.
     *
     * @param string      $message    The message to be translated
     * @param array|null  $parameters Array of parameters used to translate message
     * @param string|null $domain     The domain for the message or null to use the default
     * @param string|null $locale     The locale or null to use the default
     *
     * @throws Exception
     * @return string    The translated string
     */
    public function _(
        string $message,
        ?array $parameters = null,
        ?string $domain = null,
        ?string $locale = null
    ): string {
        if (null === $this->translator) {
            throw new Exception('Translator for TranslatorI18NextTrait must be defined with setTranslator');
        }
        return $this->translator->_($message, $parameters, $domain, $locale);
    }
}