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 a7fef52

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

File tree

Expand file treeCollapse file tree

2 files changed

+22
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+22
-8
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
+19-7Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@ 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);
35+
$args = \func_get_args();
36+
if (isset($args[0])) {
37+
if ($args[0] instanceof MessageSelector) {
38+
@trigger_error(sprintf('Calling "%s()" is with a %s deprecated since Symfony 4.3.', MessageSelector::class, __METHOD__), E_USER_DEPRECATED);
39+
$this->selector = $args[0];
40+
} elseif (\is_bool($args[0])) {
41+
$this->debug = $args[0];
42+
}
3843
}
3944
}
4045

@@ -50,8 +55,15 @@ public function transChoice($id, $number, array $parameters = [], $domain = null
5055
if ($this->selector) {
5156
return strtr($this->selector->choose((string) $id, $number, $locale ?: $this->getLocale()), $parameters);
5257
}
58+
try {
59+
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
60+
} catch (\InvalidArgumentException $e) {
61+
if ($this->debug) {
62+
throw $e;
63+
}
5364

54-
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
65+
return '';
66+
}
5567
}
5668

5769
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.