Debian Codegraph @

lib/3rdParty/composer/symfony/translation/TranslatableMessage.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;
13
14 use Symfony\Contracts\Translation\TranslatableInterface;
15 use Symfony\Contracts\Translation\TranslatorInterface;
16
17 /**
18 * @author Nate Wiebe <[email protected]>
19 */
20 class TranslatableMessage implements TranslatableInterface
21 {
22 public function __construct(
23 private string $message,
24 private array $parameters = [],
25 private ?string $domain = null,
26 ) {
27 }
28
29 /**
30 * @deprecated since Symfony 7.4
31 */
32 public function __toString(): string
33 {
34 trigger_deprecation('symfony/translation', '7.4', 'Method "%s()" is deprecated.', __METHOD__);
35
36 return $this->getMessage();
37 }
38
39 public function getMessage(): string
40 {
41 return $this->message;
42 }
43
44 public function getParameters(): array
45 {
46 return $this->parameters;
47 }
48
49 public function getDomain(): ?string
50 {
51 return $this->domain;
52 }
53
54 public function trans(TranslatorInterface $translator, ?string $locale = null): string
55 {
56 $parameters = $this->getParameters();
57 foreach ($parameters as $k => $v) {
58 if ($v instanceof TranslatableInterface) {
59 $parameters[$k] = $v->trans($translator, $locale);
60 }
61 }
62
63 return $translator->trans($this->getMessage(), $parameters, $this->getDomain(), $locale);
64 }
65 }