IdentityTranslator.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use Symfony\Contracts\Translation\TranslatorTrait;
  14. /**
  15. * IdentityTranslator does not translate anything.
  16. *
  17. * @author Fabien Potencier <fabien@symfony.com>
  18. */
  19. class IdentityTranslator implements LegacyTranslatorInterface, TranslatorInterface
  20. {
  21. use TranslatorTrait;
  22. private $selector;
  23. /**
  24. * @param MessageSelector|null $selector The message selector for pluralization
  25. */
  26. public function __construct(MessageSelector $selector = null)
  27. {
  28. $this->selector = $selector;
  29. if (__CLASS__ !== \get_class($this)) {
  30. @trigger_error(sprintf('Calling "%s()" is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
  31. }
  32. }
  33. /**
  34. * {@inheritdoc}
  35. *
  36. * @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
  37. */
  38. public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
  39. {
  40. @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%%count%%" parameter.', __METHOD__), E_USER_DEPRECATED);
  41. if ($this->selector) {
  42. return strtr($this->selector->choose((string) $id, $number, $locale ?: $this->getLocale()), $parameters);
  43. }
  44. return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
  45. }
  46. private function getPluralizationRule(int $number, string $locale): int
  47. {
  48. return PluralizationRules::get($number, $locale, false);
  49. }
  50. }