Debian Codegraph @

lib/3rdParty/composer/symfony/translation/Formatter/MessageFormatter.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Translation\Formatter;
13
14 use Symfony\Component\Translation\IdentityTranslator;
15 use Symfony\Contracts\Translation\TranslatorInterface;
16
17 // Help opcache.preload discover always-needed symbols
18 class_exists(IntlFormatter::class);
19
20 /**
21 * @author Abdellatif Ait boudad <[email protected]>
22 */
23 class MessageFormatter implements MessageFormatterInterface, IntlFormatterInterface
24 {
25 private TranslatorInterface $translator;
26 private IntlFormatterInterface $intlFormatter;
27
28 /**
29 * @param TranslatorInterface|null $translator An identity translator to use as selector for pluralization
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 }