0
0

IdentityTranslator.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. trans as private doTrans;
  23. setLocale as private doSetLocale;
  24. }
  25. private $selector;
  26. public function __construct(MessageSelector $selector = null)
  27. {
  28. $this->selector = $selector;
  29. if (__CLASS__ !== static::class) {
  30. @trigger_error(sprintf('Calling "%s()" is deprecated since Symfony 4.2.', __METHOD__), \E_USER_DEPRECATED);
  31. }
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function trans($id, array $parameters = [], $domain = null, $locale = null)
  37. {
  38. return $this->doTrans($id, $parameters, $domain, $locale);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function setLocale($locale)
  44. {
  45. $this->doSetLocale($locale);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. *
  50. * @deprecated since Symfony 4.2, use the trans() method instead with a %count% parameter
  51. */
  52. public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null)
  53. {
  54. @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);
  55. if ($this->selector) {
  56. return strtr($this->selector->choose((string) $id, $number, $locale ?: $this->getLocale()), $parameters);
  57. }
  58. return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
  59. }
  60. private function getPluralizationRule(float $number, string $locale): int
  61. {
  62. return PluralizationRules::get($number, $locale, false);
  63. }
  64. }