You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

3 years ago
  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. }