/wp-content/plugins/google-calendar-events/third-party/symfony/translation/Formatter/MessageFormatter.php

https://github.com/livinglab/openlab · PHP · 49 lines · 26 code · 2 blank · 21 comment · 1 complexity · e29b0dfe85fbb0b4bfcd58c43cce70a3 MD5 · raw file

  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 SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter;
  11. use SimpleCalendar\plugin_deps\Symfony\Component\Translation\IdentityTranslator;
  12. use SimpleCalendar\plugin_deps\Symfony\Contracts\Translation\TranslatorInterface;
  13. // Help opcache.preload discover always-needed symbols
  14. \class_exists(\SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter\IntlFormatter::class);
  15. /**
  16. * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
  17. */
  18. class MessageFormatter implements \SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter\MessageFormatterInterface, \SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter\IntlFormatterInterface
  19. {
  20. private $translator;
  21. private $intlFormatter;
  22. /**
  23. * @param TranslatorInterface|null $translator An identity translator to use as selector for pluralization
  24. */
  25. public function __construct(TranslatorInterface $translator = null, \SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter\IntlFormatterInterface $intlFormatter = null)
  26. {
  27. $this->translator = $translator ?? new IdentityTranslator();
  28. $this->intlFormatter = $intlFormatter ?? new \SimpleCalendar\plugin_deps\Symfony\Component\Translation\Formatter\IntlFormatter();
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function format(string $message, string $locale, array $parameters = [])
  34. {
  35. if ($this->translator instanceof TranslatorInterface) {
  36. return $this->translator->trans($message, $parameters, null, $locale);
  37. }
  38. return \strtr($message, $parameters);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function formatIntl(string $message, string $locale, array $parameters = []) : string
  44. {
  45. return $this->intlFormatter->formatIntl($message, $locale, $parameters);
  46. }
  47. }