Catalogue
1 month ago
Command
1 month ago
DataCollector
1 month ago
DependencyInjection
1 month ago
Dumper
1 month ago
Exception
1 month ago
Extractor
1 month ago
Formatter
1 month ago
Loader
1 month ago
Provider
1 month ago
Reader
1 month ago
Resources
1 month ago
Test
1 month ago
Util
1 month ago
Writer
1 month ago
DataCollectorTranslator.php
1 month ago
IdentityTranslator.php
2 years ago
LoggingTranslator.php
1 month ago
MessageCatalogue.php
1 month ago
MessageCatalogueInterface.php
1 month ago
MetadataAwareInterface.php
1 month ago
PseudoLocalizationTranslator.php
1 month ago
TranslatableMessage.php
1 month ago
Translator.php
1 month ago
TranslatorBag.php
1 month ago
TranslatorBagInterface.php
1 month ago
TranslatableMessage.php
53 lines
| 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 | namespace IAWPSCOPED\Symfony\Component\Translation; |
| 12 | |
| 13 | use IAWPSCOPED\Symfony\Contracts\Translation\TranslatableInterface; |
| 14 | use IAWPSCOPED\Symfony\Contracts\Translation\TranslatorInterface; |
| 15 | /** |
| 16 | * @author Nate Wiebe <nate@northern.co> |
| 17 | * @internal |
| 18 | */ |
| 19 | class TranslatableMessage implements TranslatableInterface |
| 20 | { |
| 21 | private string $message; |
| 22 | private array $parameters; |
| 23 | private ?string $domain; |
| 24 | public function __construct(string $message, array $parameters = [], string $domain = null) |
| 25 | { |
| 26 | $this->message = $message; |
| 27 | $this->parameters = $parameters; |
| 28 | $this->domain = $domain; |
| 29 | } |
| 30 | public function __toString() : string |
| 31 | { |
| 32 | return $this->getMessage(); |
| 33 | } |
| 34 | public function getMessage() : string |
| 35 | { |
| 36 | return $this->message; |
| 37 | } |
| 38 | public function getParameters() : array |
| 39 | { |
| 40 | return $this->parameters; |
| 41 | } |
| 42 | public function getDomain() : ?string |
| 43 | { |
| 44 | return $this->domain; |
| 45 | } |
| 46 | public function trans(TranslatorInterface $translator, string $locale = null) : string |
| 47 | { |
| 48 | return $translator->trans($this->getMessage(), \array_map(static function ($parameter) use($translator, $locale) { |
| 49 | return $parameter instanceof TranslatableInterface ? $parameter->trans($translator, $locale) : $parameter; |
| 50 | }, $this->getParameters()), $this->getDomain(), $locale); |
| 51 | } |
| 52 | } |
| 53 |