| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Translation\Formatter; |
| 13 |
|
| 14 |
use Symfony\Component\Translation\IdentityTranslator; |
| 15 |
use Symfony\Contracts\Translation\TranslatorInterface; |
| 16 |
|
| 17 |
|
| 18 |
class_exists(IntlFormatter::class); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterface |
| 24 |
{ |
| 25 |
private TranslatorInterface $translator; |
| 26 |
private IntlFormatterInterface $intlFormatter; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public function __construct(?TranslatorInterface $translator = null, ?IntlFormatterInterface $intlFormatter = null) |
| 32 |
{ |
| 33 |
$this->translator = $translator ?? new IdentityTranslator(); |
| 34 |
$this->intlFormatter = $intlFormatter ?? new IntlFormatter(); |
| 35 |
} |
| 36 |
|
| 37 |
public function format(string $message, string $locale, array $parameters = []): string |
| 38 |
{ |
| 39 |
return $this->translator->trans($message, $parameters, null, $locale); |
| 40 |
} |
| 41 |
|
| 42 |
public function formatIntl(string $message, string $locale, array $parameters = []): string |
| 43 |
{ |
| 44 |
return $this->intlFormatter->formatIntl($message, $locale, $parameters); |
| 45 |
} |
| 46 |
} |