TranslatableMessage.php 1.3 KB

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