0 follower

Final Class Yiisoft\TranslatorExtractor\CategorySource

InheritanceYiisoft\TranslatorExtractor\CategorySource

Represents message category for reading and writing messages.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string $name, \Yiisoft\Translator\MessageReaderInterface $reader, \Yiisoft\Translator\MessageWriterInterface $writer )
$name string

Category name.

$reader \Yiisoft\Translator\MessageReaderInterface
$writer \Yiisoft\Translator\MessageWriterInterface

                public function __construct(
    private string $name,
    private MessageReaderInterface $reader,
    private MessageWriterInterface $writer
) {
    if (!preg_match('/^[a-z0-9_-]+$/i', $name)) {
        throw new RuntimeException(
            'Category name is invalid. Only letters, numbers, dash, and underscore are allowed.'
        );
    }
}

            
getName() public method

public string getName ( )
return string

Category name.

                public function getName(): string
{
    return $this->name;
}

            
readMessages() public method

public array readMessages ( string $category, string $locale )
$category string

Category of messages to get.

$locale string

Locale of messages to get.

return array

All messages from category. The format is the same as in {@see \Yiisoft\Translator\MessageReaderInterface::getMessages()}.

                public function readMessages(string $category, string $locale): array
{
    return $this->reader->getMessages($category, $locale);
}

            
writeMessages() public method

See also \Yiisoft\Translator\MessageWriterInterface::write.

public void writeMessages ( string $category, string $locale, array $messages )
$category string

Category to write messages to.

$locale string

Locale to write messages for.

$messages array

Messages to write.

                public function writeMessages(string $category, string $locale, array $messages): void
{
    $this->writer->write($category, $locale, $messages);
}