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 c3d6800

Browse filesBrowse files
Amrouche HamzaSimperfit
Amrouche Hamza
authored andcommitted
[Translation] TransChoice invalide plural translation
1 parent 491c0d5 commit c3d6800
Copy full SHA for c3d6800

File tree

3 files changed

+24
-10
lines changed
Filter options

3 files changed

+24
-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
@@ -48,7 +48,7 @@
4848
"symfony/security-http": "^3.4|^4.0|^5.0",
4949
"symfony/serializer": "^4.3|^5.0",
5050
"symfony/stopwatch": "^3.4|^4.0|^5.0",
51-
"symfony/translation": "^4.2|^5.0",
51+
"symfony/translation": "^4.4|^5.0",
5252
"symfony/templating": "^3.4|^4.0|^5.0",
5353
"symfony/twig-bundle": "^3.4|^4.0|^5.0",
5454
"symfony/validator": "^4.1|^5.0",
@@ -76,7 +76,7 @@
7676
"symfony/property-info": "<3.4",
7777
"symfony/serializer": "<4.2",
7878
"symfony/stopwatch": "<3.4",
79-
"symfony/translation": "<4.3",
79+
"symfony/translation": "<4.4",
8080
"symfony/twig-bridge": "<4.1.1",
8181
"symfony/validator": "<4.1",
8282
"symfony/workflow": "<4.3"

‎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+
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

@@ -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 strtr($id, $parameters);
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.