blob: 82ae6d7243885a219d3795429dd4bd14cef29c7a [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Translation;
13
14use Symfony\Contracts\Translation\TranslatableInterface;
15use Symfony\Contracts\Translation\TranslatorInterface;
16
17/**
18 * @author Nate Wiebe <nate@northern.co>
19 */
20class TranslatableMessage implements TranslatableInterface
21{
22 private $message;
23 private $parameters;
24 private $domain;
25
26 public function __construct(string $message, array $parameters = [], string $domain = null)
27 {
28 $this->message = $message;
29 $this->parameters = $parameters;
30 $this->domain = $domain;
31 }
32
33 public function __toString(): string
34 {
35 return $this->getMessage();
36 }
37
38 public function getMessage(): string
39 {
40 return $this->message;
41 }
42
43 public function getParameters(): array
44 {
45 return $this->parameters;
46 }
47
48 public function getDomain(): ?string
49 {
50 return $this->domain;
51 }
52
53 public function trans(TranslatorInterface $translator, string $locale = null): string
54 {
55 return $translator->trans($this->getMessage(), $this->getParameters(), $this->getDomain(), $locale);
56 }
57}