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 __construct( string $name, \Yiisoft\Translator\MessageReaderInterface $reader, \Yiisoft\Translator\MessageWriterInterface $writer ): mixed
$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 getName( ): string
return string

Category name.

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

            
readMessages() public method

public readMessages( string $category, string $locale ): array
$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 \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 writeMessages( string $category, string $locale, array $messages ): void
$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);
}