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 47d6d7e

Browse filesBrowse files
Amrouche HamzaSimperfit
Amrouche Hamza
authored andcommitted
[Translation] TransChoice invalide plural translation
1 parent ba988ac commit 47d6d7e
Copy full SHA for 47d6d7e

File tree

Expand file treeCollapse file tree

4 files changed

+44
-10
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+44
-10
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/Bundle/FrameworkBundle/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"symfony/security-http": "^3.4|^4.0|^5.0",
5050
"symfony/serializer": "^4.3|^5.0",
5151
"symfony/stopwatch": "^3.4|^4.0|^5.0",
52-
"symfony/translation": "^4.3|^5.0",
52+
"symfony/translation": "^4.4|^5.0",
5353
"symfony/templating": "^3.4|^4.0|^5.0",
5454
"symfony/twig-bundle": "^3.4|^4.0|^5.0",
5555
"symfony/validator": "^4.1|^5.0",
@@ -79,7 +79,7 @@
7979
"symfony/property-info": "<3.4",
8080
"symfony/serializer": "<4.2",
8181
"symfony/stopwatch": "<3.4",
82-
"symfony/translation": "<4.3",
82+
"symfony/translation": "<4.4",
8383
"symfony/twig-bridge": "<4.1.1",
8484
"symfony/validator": "<4.1",
8585
"symfony/workflow": "<4.3"

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/IdentityTranslator.php
+20-7Lines changed: 20 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+
if (null === $debug || $debug instanceof MessageSelector) {
36+
@trigger_error(sprintf('Passing a %s instance or null to %s() is deprecated since Symfony 4.4.', MessageSelector::class, __METHOD__), E_USER_DEPRECATED);
37+
$this->selector = $debug;
38+
$this->debug = true;
39+
} elseif (!\is_bool($debug)) {
40+
throw new \TypeError(sprintf('The first argument of %s() must be a boolean.', __METHOD__));
41+
} else {
42+
$this->debug = $debug;
3843
}
3944
}
4045

@@ -51,7 +56,15 @@ public function transChoice($id, $number, array $parameters = [], $domain = null
5156
return strtr($this->selector->choose((string) $id, $number, $locale ?: $this->getLocale()), $parameters);
5257
}
5358

54-
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
59+
try {
60+
return $this->trans($id, ['%count%' => $number] + $parameters, $domain, $locale);
61+
} catch (\InvalidArgumentException $e) {
62+
if ($this->debug) {
63+
throw $e;
64+
}
65+
66+
return strtr($id, $parameters);
67+
}
5568
}
5669

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

‎src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/Tests/IdentityTranslatorTest.php
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,23 @@ public function getTranslator()
2020
{
2121
return new IdentityTranslator();
2222
}
23+
24+
/**
25+
* @group legacy
26+
*/
27+
public function testDebugNotThrow()
28+
{
29+
$identityTranslator = new IdentityTranslator(false);
30+
$this->assertSame('', $identityTranslator->transChoice('',1, []));
31+
}
32+
33+
/**
34+
* @group legacy
35+
* @expectedException \Symfony\Component\Translation\Exception\InvalidArgumentException
36+
*/
37+
public function testDebugThrow()
38+
{
39+
$identityTranslator = new IdentityTranslator(true);
40+
$identityTranslator->transChoice('',1, []);
41+
}
2342
}

0 commit comments

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