Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony/translation/Translator.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Symfony\Component\Translation; | 12 namespace Symfony\Component\Translation; |
13 | 13 |
14 use Symfony\Component\Translation\Loader\LoaderInterface; | 14 use Symfony\Component\Config\ConfigCacheFactory; |
15 use Symfony\Component\Translation\Exception\NotFoundResourceException; | 15 use Symfony\Component\Config\ConfigCacheFactoryInterface; |
16 use Symfony\Component\Config\ConfigCacheInterface; | |
16 use Symfony\Component\Translation\Exception\InvalidArgumentException; | 17 use Symfony\Component\Translation\Exception\InvalidArgumentException; |
17 use Symfony\Component\Translation\Exception\LogicException; | 18 use Symfony\Component\Translation\Exception\LogicException; |
19 use Symfony\Component\Translation\Exception\NotFoundResourceException; | |
18 use Symfony\Component\Translation\Exception\RuntimeException; | 20 use Symfony\Component\Translation\Exception\RuntimeException; |
19 use Symfony\Component\Config\ConfigCacheInterface; | |
20 use Symfony\Component\Config\ConfigCacheFactoryInterface; | |
21 use Symfony\Component\Config\ConfigCacheFactory; | |
22 use Symfony\Component\Translation\Formatter\MessageFormatterInterface; | |
23 use Symfony\Component\Translation\Formatter\ChoiceMessageFormatterInterface; | 21 use Symfony\Component\Translation\Formatter\ChoiceMessageFormatterInterface; |
24 use Symfony\Component\Translation\Formatter\MessageFormatter; | 22 use Symfony\Component\Translation\Formatter\MessageFormatter; |
23 use Symfony\Component\Translation\Formatter\MessageFormatterInterface; | |
24 use Symfony\Component\Translation\Loader\LoaderInterface; | |
25 | 25 |
26 /** | 26 /** |
27 * @author Fabien Potencier <fabien@symfony.com> | 27 * @author Fabien Potencier <fabien@symfony.com> |
28 */ | 28 */ |
29 class Translator implements TranslatorInterface, TranslatorBagInterface | 29 class Translator implements TranslatorInterface, TranslatorBagInterface |
30 { | 30 { |
31 /** | 31 /** |
32 * @var MessageCatalogueInterface[] | 32 * @var MessageCatalogueInterface[] |
33 */ | 33 */ |
34 protected $catalogues = array(); | 34 protected $catalogues = []; |
35 | 35 |
36 /** | 36 /** |
37 * @var string | 37 * @var string |
38 */ | 38 */ |
39 private $locale; | 39 private $locale; |
40 | 40 |
41 /** | 41 /** |
42 * @var array | 42 * @var array |
43 */ | 43 */ |
44 private $fallbackLocales = array(); | 44 private $fallbackLocales = []; |
45 | 45 |
46 /** | 46 /** |
47 * @var LoaderInterface[] | 47 * @var LoaderInterface[] |
48 */ | 48 */ |
49 private $loaders = array(); | 49 private $loaders = []; |
50 | 50 |
51 /** | 51 /** |
52 * @var array | 52 * @var array |
53 */ | 53 */ |
54 private $resources = array(); | 54 private $resources = []; |
55 | 55 |
56 /** | 56 /** |
57 * @var MessageFormatterInterface | 57 * @var MessageFormatterInterface |
58 */ | 58 */ |
59 private $formatter; | 59 private $formatter; |
85 { | 85 { |
86 $this->setLocale($locale); | 86 $this->setLocale($locale); |
87 | 87 |
88 if ($formatter instanceof MessageSelector) { | 88 if ($formatter instanceof MessageSelector) { |
89 $formatter = new MessageFormatter($formatter); | 89 $formatter = new MessageFormatter($formatter); |
90 @trigger_error(sprintf('Passing a "%s" instance into the "%s" as a second argument is deprecated since Symfony 3.4 and will be removed in 4.0. Inject a "%s" implementation instead.', MessageSelector::class, __METHOD__, MessageFormatterInterface::class), E_USER_DEPRECATED); | 90 @trigger_error(sprintf('Passing a "%s" instance into the "%s()" method as a second argument is deprecated since Symfony 3.4 and will be removed in 4.0. Inject a "%s" implementation instead.', MessageSelector::class, __METHOD__, MessageFormatterInterface::class), E_USER_DEPRECATED); |
91 } elseif (null === $formatter) { | 91 } elseif (null === $formatter) { |
92 $formatter = new MessageFormatter(); | 92 $formatter = new MessageFormatter(); |
93 } | 93 } |
94 | 94 |
95 $this->formatter = $formatter; | 95 $this->formatter = $formatter; |
129 $domain = 'messages'; | 129 $domain = 'messages'; |
130 } | 130 } |
131 | 131 |
132 $this->assertValidLocale($locale); | 132 $this->assertValidLocale($locale); |
133 | 133 |
134 $this->resources[$locale][] = array($format, $resource, $domain); | 134 $this->resources[$locale][] = [$format, $resource, $domain]; |
135 | 135 |
136 if (in_array($locale, $this->fallbackLocales)) { | 136 if (\in_array($locale, $this->fallbackLocales)) { |
137 $this->catalogues = array(); | 137 $this->catalogues = []; |
138 } else { | 138 } else { |
139 unset($this->catalogues[$locale]); | 139 unset($this->catalogues[$locale]); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
165 * @throws InvalidArgumentException If a locale contains invalid characters | 165 * @throws InvalidArgumentException If a locale contains invalid characters |
166 */ | 166 */ |
167 public function setFallbackLocales(array $locales) | 167 public function setFallbackLocales(array $locales) |
168 { | 168 { |
169 // needed as the fallback locales are linked to the already loaded catalogues | 169 // needed as the fallback locales are linked to the already loaded catalogues |
170 $this->catalogues = array(); | 170 $this->catalogues = []; |
171 | 171 |
172 foreach ($locales as $locale) { | 172 foreach ($locales as $locale) { |
173 $this->assertValidLocale($locale); | 173 $this->assertValidLocale($locale); |
174 } | 174 } |
175 | 175 |
177 } | 177 } |
178 | 178 |
179 /** | 179 /** |
180 * Gets the fallback locales. | 180 * Gets the fallback locales. |
181 * | 181 * |
182 * @return array $locales The fallback locales | 182 * @return array The fallback locales |
183 */ | 183 */ |
184 public function getFallbackLocales() | 184 public function getFallbackLocales() |
185 { | 185 { |
186 return $this->fallbackLocales; | 186 return $this->fallbackLocales; |
187 } | 187 } |
188 | 188 |
189 /** | 189 /** |
190 * {@inheritdoc} | 190 * {@inheritdoc} |
191 */ | 191 */ |
192 public function trans($id, array $parameters = array(), $domain = null, $locale = null) | 192 public function trans($id, array $parameters = [], $domain = null, $locale = null) |
193 { | 193 { |
194 if (null === $domain) { | 194 if (null === $domain) { |
195 $domain = 'messages'; | 195 $domain = 'messages'; |
196 } | 196 } |
197 | 197 |
199 } | 199 } |
200 | 200 |
201 /** | 201 /** |
202 * {@inheritdoc} | 202 * {@inheritdoc} |
203 */ | 203 */ |
204 public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) | 204 public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null) |
205 { | 205 { |
206 if (!$this->formatter instanceof ChoiceMessageFormatterInterface) { | 206 if (!$this->formatter instanceof ChoiceMessageFormatterInterface) { |
207 throw new LogicException(sprintf('The formatter "%s" does not support plural translations.', get_class($this->formatter))); | 207 throw new LogicException(sprintf('The formatter "%s" does not support plural translations.', \get_class($this->formatter))); |
208 } | 208 } |
209 | 209 |
210 if (null === $domain) { | 210 if (null === $domain) { |
211 $domain = 'messages'; | 211 $domain = 'messages'; |
212 } | 212 } |
401 } | 401 } |
402 } | 402 } |
403 | 403 |
404 protected function computeFallbackLocales($locale) | 404 protected function computeFallbackLocales($locale) |
405 { | 405 { |
406 $locales = array(); | 406 $locales = []; |
407 foreach ($this->fallbackLocales as $fallback) { | 407 foreach ($this->fallbackLocales as $fallback) { |
408 if ($fallback === $locale) { | 408 if ($fallback === $locale) { |
409 continue; | 409 continue; |
410 } | 410 } |
411 | 411 |
412 $locales[] = $fallback; | 412 $locales[] = $fallback; |
413 } | 413 } |
414 | 414 |
415 if (false !== strrchr($locale, '_')) { | 415 if (false !== strrchr($locale, '_')) { |
416 array_unshift($locales, substr($locale, 0, -strlen(strrchr($locale, '_')))); | 416 array_unshift($locales, substr($locale, 0, -\strlen(strrchr($locale, '_')))); |
417 } | 417 } |
418 | 418 |
419 return array_unique($locales); | 419 return array_unique($locales); |
420 } | 420 } |
421 | 421 |