Final Class Yiisoft\TranslatorExtractor\CategorySource
| Inheritance | Yiisoft\TranslatorExtractor\CategorySource |
|---|
Represents message category for reading and writing messages.
Public Methods
Method Details
| 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.'
);
}
}
| public string getName ( ) | ||
| return | string |
Category name. |
|---|---|---|
public function getName(): string
{
return $this->name;
}
| 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);
}
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);
}
Signup or Login in order to comment.