Final Class Yiisoft\Translator\Message\Php\MessageSource
| Inheritance | Yiisoft\Translator\Message\Php\MessageSource |
|---|---|
| Implements | Yiisoft\Translator\MessageReaderInterface, Yiisoft\Translator\MessageWriterInterface |
Public Methods
Method Details
| public mixed __construct ( string $path ) | ||
| $path | string | |
public function __construct(private string $path)
{
}
| public string|null getMessage ( string $id, string $category, string $locale, array $parameters = [] ) | ||
| $id | string | |
| $category | string | |
| $locale | string | |
| $parameters | array | |
public function getMessage(string $id, string $category, string $locale, array $parameters = []): ?string
{
if (!isset($this->messages[$category][$locale])) {
$this->read($category, $locale);
}
return $this->messages[$category][$locale][$id] ?? null;
}
| public array getMessages ( string $category, string $locale ) | ||
| $category | string | |
| $locale | string | |
public function getMessages(string $category, string $locale): array
{
if (!isset($this->messages[$category][$locale])) {
$this->read($category, $locale);
}
$messages = $this->messages[$category][$locale] ?? [];
foreach ($messages as &$message) {
$message = ['message' => $message];
}
/** @psalm-var array<string, array<string, string>> $messages */
return $messages;
}
| public void write ( string $category, string $locale, array $messages ) | ||
| $category | string | |
| $locale | string | |
| $messages | array | |
public function write(string $category, string $locale, array $messages): void
{
$content = $this->generateMessagesFileContent($messages);
$path = $this->getFilePath($category, $locale, true);
if (file_put_contents($path, $content, LOCK_EX) === false) {
throw new RuntimeException('Can not write to ' . $path);
}
}
Signup or Login in order to comment.