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 0732cc5

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

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+23
-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
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
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>null</argument>
15+
<argument>%kernel.debug%</argument>
16+
</service>
1417
<service id="translator.selector" class="Symfony\Component\Translation\MessageSelector">
1518
<deprecated>The "%service_id%" service is deprecated since Symfony 4.2, use "identity_translator" instead.</deprecated>
1619
</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+
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.