1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace Symfony\Component\Translation\Formatter;
- use Symfony\Component\Translation\IdentityTranslator;
- use Symfony\Contracts\Translation\TranslatorInterface;
- class_exists(IntlFormatter::class);
- class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterface
- {
- private $translator;
- private $intlFormatter;
-
- 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 = [])
- {
- if ($this->translator instanceof TranslatorInterface) {
- return $this->translator->trans($message, $parameters, null, $locale);
- }
- return strtr($message, $parameters);
- }
-
- public function formatIntl(string $message, string $locale, array $parameters = []): string
- {
- return $this->intlFormatter->formatIntl($message, $locale, $parameters);
- }
- }
|