Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?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
 
12
namespace Symfony\Component\Translation;
13
 
14
use Symfony\Contracts\Translation\TranslatableInterface;
15
use Symfony\Contracts\Translation\TranslatorInterface;
16
 
17
/**
18
 * @author Nate Wiebe <nate@northern.co>
19
 */
20
class TranslatableMessage implements TranslatableInterface
21
{
22
    private string $message;
23
    private array $parameters;
24
    private ?string $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(), array_map(
56
            static function ($parameter) use ($translator, $locale) {
57
                return $parameter instanceof TranslatableInterface ? $parameter->trans($translator, $locale) : $parameter;
58
            },
59
            $this->getParameters()
60
        ), $this->getDomain(), $locale);
61
    }
62
}