Drupal investigation

IdentityTranslator.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /**
  12. * IdentityTranslator does not translate anything.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class IdentityTranslator implements TranslatorInterface
  17. {
  18. private $selector;
  19. private $locale;
  20. /**
  21. * Constructor.
  22. *
  23. * @param MessageSelector|null $selector The message selector for pluralization
  24. */
  25. public function __construct(MessageSelector $selector = null)
  26. {
  27. $this->selector = $selector ?: new MessageSelector();
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function setLocale($locale)
  33. {
  34. $this->locale = $locale;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getLocale()
  40. {
  41. return $this->locale ?: \Locale::getDefault();
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function trans($id, array $parameters = array(), $domain = null, $locale = null)
  47. {
  48. return strtr((string) $id, $parameters);
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
  54. {
  55. return strtr($this->selector->choose((string) $id, (int) $number, $locale ?: $this->getLocale()), $parameters);
  56. }
  57. }