comparison vendor/symfony/translation/IdentityTranslator.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Translation;
13
14 /**
15 * IdentityTranslator does not translate anything.
16 *
17 * @author Fabien Potencier <fabien@symfony.com>
18 */
19 class IdentityTranslator implements TranslatorInterface
20 {
21 private $selector;
22 private $locale;
23
24 /**
25 * Constructor.
26 *
27 * @param MessageSelector|null $selector The message selector for pluralization
28 */
29 public function __construct(MessageSelector $selector = null)
30 {
31 $this->selector = $selector ?: new MessageSelector();
32 }
33
34 /**
35 * {@inheritdoc}
36 */
37 public function setLocale($locale)
38 {
39 $this->locale = $locale;
40 }
41
42 /**
43 * {@inheritdoc}
44 */
45 public function getLocale()
46 {
47 return $this->locale ?: \Locale::getDefault();
48 }
49
50 /**
51 * {@inheritdoc}
52 */
53 public function trans($id, array $parameters = array(), $domain = null, $locale = null)
54 {
55 return strtr((string) $id, $parameters);
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
62 {
63 return strtr($this->selector->choose((string) $id, (int) $number, $locale ?: $this->getLocale()), $parameters);
64 }
65 }