class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterface
{ private TranslatorInterface
$translator;
private IntlFormatterInterface
$intlFormatter;
/**
* @param TranslatorInterface|null $translator An identity translator to use as selector for pluralization
*/
public function __construct(TranslatorInterface
$translator = null, IntlFormatterInterface
$intlFormatter = null
) { $this->translator =
$translator ??
new IdentityTranslator();
$this->intlFormatter =
$intlFormatter ??
new IntlFormatter();
} public function format(string
$message, string
$locale, array
$parameters =
[]): string
{ if ($this->translator instanceof TranslatorInterface
) { return $this->translator->
trans($message,
$parameters, null,
$locale);
} return strtr($message,
$parameters);
}