0

Final Class Yiisoft\Yii\DataView\DefaultTranslatorFactory

InheritanceYiisoft\Yii\DataView\DefaultTranslatorFactory

Creates the translator used by widgets when none is passed explicitly.

Method Details

Hide inherited methods

create() public static method

public static \Yiisoft\Translator\TranslatorInterface create ( string $category )
$category string

A name for {@see \Yiisoft\Translator\CategorySource} to register in the translator.

return \Yiisoft\Translator\TranslatorInterface

Translator instance used for translations of messages.

                public static function create(string $category): TranslatorInterface
{
    $categorySource = new CategorySource(
        $category,
        new IdMessageReader(),
        extension_loaded('intl') ? new IntlMessageFormatter() : new SimpleMessageFormatter(),
    );
    $translator = new Translator();
    $translator->addCategorySources($categorySource);
    return $translator;
}