updated-packages
This commit is contained in:
@@ -28,5 +28,5 @@ interface ChoiceMessageFormatterInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function choiceFormat($message, $number, $locale, array $parameters = array());
|
||||
public function choiceFormat($message, $number, $locale, array $parameters = []);
|
||||
}
|
||||
|
@@ -21,13 +21,18 @@ use Symfony\Component\Translation\Exception\LogicException;
|
||||
class IntlFormatter implements IntlFormatterInterface
|
||||
{
|
||||
private $hasMessageFormatter;
|
||||
private $cache = array();
|
||||
private $cache = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatIntl(string $message, string $locale, array $parameters = array()): string
|
||||
public function formatIntl(string $message, string $locale, array $parameters = []): string
|
||||
{
|
||||
// MessageFormatter constructor throws an exception if the message is empty
|
||||
if ('' === $message) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!$formatter = $this->cache[$locale][$message] ?? null) {
|
||||
if (!($this->hasMessageFormatter ?? $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.');
|
||||
@@ -35,19 +40,19 @@ class IntlFormatter implements IntlFormatterInterface
|
||||
try {
|
||||
$this->cache[$locale][$message] = $formatter = new \MessageFormatter($locale, $message);
|
||||
} catch (\IntlException $e) {
|
||||
throw new InvalidArgumentException(sprintf('Invalid message format (error #%d): %s.', intl_get_error_code(), intl_get_error_message()), 0, $e);
|
||||
throw new InvalidArgumentException(sprintf('Invalid message format (error #%d): ', intl_get_error_code()).intl_get_error_message(), 0, $e);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($parameters as $key => $value) {
|
||||
if (\in_array($key[0] ?? null, array('%', '{'), true)) {
|
||||
if (\in_array($key[0] ?? null, ['%', '{'], true)) {
|
||||
unset($parameters[$key]);
|
||||
$parameters[trim($key, '%{ }')] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (false === $message = $formatter->format($parameters)) {
|
||||
throw new InvalidArgumentException(sprintf('Unable to format message (error #%s): %s.', $formatter->getErrorCode(), $formatter->getErrorMessage()));
|
||||
throw new InvalidArgumentException(sprintf('Unable to format message (error #%s): ', $formatter->getErrorCode()).$formatter->getErrorMessage());
|
||||
}
|
||||
|
||||
return $message;
|
||||
|
@@ -23,5 +23,5 @@ interface IntlFormatterInterface
|
||||
*
|
||||
* @see http://icu-project.org/apiref/icu4c/classMessageFormat.html#details
|
||||
*/
|
||||
public function formatIntl(string $message, string $locale, array $parameters = array()): string;
|
||||
public function formatIntl(string $message, string $locale, array $parameters = []): string;
|
||||
}
|
||||
|
@@ -16,6 +16,9 @@ use Symfony\Component\Translation\MessageSelector;
|
||||
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
// Help opcache.preload discover always-needed symbols
|
||||
class_exists(IntlFormatter::class);
|
||||
|
||||
/**
|
||||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
||||
*/
|
||||
@@ -32,7 +35,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
if ($translator instanceof MessageSelector) {
|
||||
$translator = new IdentityTranslator($translator);
|
||||
} elseif (null !== $translator && !$translator instanceof TranslatorInterface && !$translator instanceof LegacyTranslatorInterface) {
|
||||
throw new \TypeError(sprintf('Argument 1 passed to %s() must be an instance of %s, %s given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
|
||||
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be an instance of "%s", "%s" given.', __METHOD__, TranslatorInterface::class, \is_object($translator) ? \get_class($translator) : \gettype($translator)));
|
||||
}
|
||||
|
||||
$this->translator = $translator ?? new IdentityTranslator();
|
||||
@@ -42,7 +45,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function format($message, $locale, array $parameters = array())
|
||||
public function format($message, $locale, array $parameters = [])
|
||||
{
|
||||
if ($this->translator instanceof TranslatorInterface) {
|
||||
return $this->translator->trans($message, $parameters, null, $locale);
|
||||
@@ -54,7 +57,7 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatIntl(string $message, string $locale, array $parameters = array()): string
|
||||
public function formatIntl(string $message, string $locale, array $parameters = []): string
|
||||
{
|
||||
return $this->intlFormatter->formatIntl($message, $locale, $parameters);
|
||||
}
|
||||
@@ -64,16 +67,16 @@ class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterf
|
||||
*
|
||||
* @deprecated since Symfony 4.2, use format() with a %count% parameter instead
|
||||
*/
|
||||
public function choiceFormat($message, $number, $locale, array $parameters = array())
|
||||
public function choiceFormat($message, $number, $locale, array $parameters = [])
|
||||
{
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %count% parameter.', __METHOD__), E_USER_DEPRECATED);
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the format() one instead with a %%count%% parameter.', __METHOD__), \E_USER_DEPRECATED);
|
||||
|
||||
$parameters = array('%count%' => $number) + $parameters;
|
||||
$parameters = ['%count%' => $number] + $parameters;
|
||||
|
||||
if ($this->translator instanceof TranslatorInterface) {
|
||||
return $this->format($message, $locale, $parameters);
|
||||
}
|
||||
|
||||
return $this->format($this->translator->transChoice($message, $number, array(), null, $locale), $locale, $parameters);
|
||||
return $this->format($this->translator->transChoice($message, $number, [], null, $locale), $locale, $parameters);
|
||||
}
|
||||
}
|
||||
|
@@ -26,5 +26,5 @@ interface MessageFormatterInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format($message, $locale, array $parameters = array());
|
||||
public function format($message, $locale, array $parameters = []);
|
||||
}
|
||||
|
Reference in New Issue
Block a user