package and depencies
This commit is contained in:
@@ -23,9 +23,6 @@ class IntlFormatter implements IntlFormatterInterface
|
||||
private $hasMessageFormatter;
|
||||
private $cache = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatIntl(string $message, string $locale, array $parameters = []): string
|
||||
{
|
||||
// MessageFormatter constructor throws an exception if the message is empty
|
||||
@@ -34,7 +31,7 @@ class IntlFormatter implements IntlFormatterInterface
|
||||
}
|
||||
|
||||
if (!$formatter = $this->cache[$locale][$message] ?? null) {
|
||||
if (!($this->hasMessageFormatter ?? $this->hasMessageFormatter = class_exists(\MessageFormatter::class))) {
|
||||
if (!$this->hasMessageFormatter ??= class_exists(\MessageFormatter::class)) {
|
||||
throw new LogicException('Cannot parse message translation: please install the "intl" PHP extension or the "symfony/polyfill-intl-messageformatter" package.');
|
||||
}
|
||||
try {
|
||||
|
@@ -22,8 +22,8 @@ class_exists(IntlFormatter::class);
|
||||
*/
|
||||
class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterface
|
||||
{
|
||||
private $translator;
|
||||
private $intlFormatter;
|
||||
private TranslatorInterface $translator;
|
||||
private IntlFormatterInterface $intlFormatter;
|
||||
|
||||
/**
|
||||
* @param TranslatorInterface|null $translator An identity translator to use as selector for pluralization
|
||||
@@ -34,10 +34,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
$this->intlFormatter = $intlFormatter ?? new IntlFormatter();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(string $message, string $locale, array $parameters = [])
|
||||
public function format(string $message, string $locale, array $parameters = []): string
|
||||
{
|
||||
if ($this->translator instanceof TranslatorInterface) {
|
||||
return $this->translator->trans($message, $parameters, null, $locale);
|
||||
@@ -46,9 +43,6 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
return strtr($message, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatIntl(string $message, string $locale, array $parameters = []): string
|
||||
{
|
||||
return $this->intlFormatter->formatIntl($message, $locale, $parameters);
|
||||
|
@@ -23,8 +23,6 @@ interface MessageFormatterInterface
|
||||
* @param string $message The message (may also be an object that can be cast to string)
|
||||
* @param string $locale The message locale
|
||||
* @param array $parameters An array of parameters for the message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(string $message, string $locale, array $parameters = []);
|
||||
public function format(string $message, string $locale, array $parameters = []): string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user