Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8a3fdb5

Browse filesBrowse files
Amrouche HamzaSimperfit
Amrouche Hamza
authored andcommitted
[Translation] TransChoice invalide plural translation
1 parent 95932df commit 8a3fdb5
Copy full SHA for 8a3fdb5

File tree

2 files changed

+20
-9
lines changed
Filter options

2 files changed

+20
-9
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/identity_translator.xml
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
<service id="Symfony\Component\Translation\TranslatorInterface" alias="translator" />
1111
<service id="Symfony\Contracts\Translation\TranslatorInterface" alias="translator" />
1212

13-
<service id="identity_translator" class="Symfony\Component\Translation\IdentityTranslator" />
13+
<service id="identity_translator" class="Symfony\Component\Translation\IdentityTranslator" >
14+
<argument>%kernel.debug%</argument>
15+
</service>
1416
<service id="translator.selector" class="Symfony\Component\Translation\MessageSelector">
1517
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2, use "identity_translator" instead.</deprecated>
1618
</service>

‎src/Symfony/Component/Translation/IdentityTranslator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/IdentityTranslator.php
+17-8Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ class IdentityTranslator implements LegacyTranslatorInterface, TranslatorInterfa
2525
use TranslatorTrait;
2626

2727
private $selector;
28+
private $debug;
2829

2930
/**
30-
* @param MessageSelector|null $selector The message selector for pluralization
31+
* @param bool $debug
3132
*/
32-
public function __construct(MessageSelector $selector = null)
33+
public function __construct($debug = true)
3334
{
34-
$this->selector = $selector;
35-
36-
if (__CLASS__ !== \get_class($this)) {
37-
@trigger_error(sprintf('Calling "%s()" is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED);
38-
}
35+
if ($debug instanceof MessageSelector) {
36+
@trigger_error(sprintf('Calling "%s()" is with a %s deprecated since Symfony 4.3.', MessageSelector::class, __METHOD__), E_USER_DEPRECATED);
37+
$this->selector = $debug;
38+
} elseif (\is_bool($debug)) {
39+
$this->debug = $debug;
40+
}
3941
}
4042

4143
/**
@@ -50,8 +52,15 @@ public function transChoice($id, $number, array $parameters = [], $domain = null
5052
if ($this->selector) {
5153
return strtr($this->selector->choose((string) $id, $number, $locale ?: $this->getLocale()), $parameters);
5254
}
55+
try {
56+
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
57+
} catch (\InvalidArgumentException $e) {
58+
if ($this->debug) {
59+
throw $e;
60+
}
5361

54-
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
62+
return '';
63+
}
5564
}
5665

5766
private function getPluralizationRule(int $number, string $locale): int

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.