Skip to content

Commit a7eac93

Browse files
Nyholmnicolas-grekas
authored andcommitted
[Translator] Deprecated transChoice and moved it away from contracts
1 parent 31a0604 commit a7eac93

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Util/LegacyTranslatorProxy.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Util;
1313

14+
use Symfony\Component\Translation\LegacyTranslatorTrait;
1415
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1516
use Symfony\Contracts\Translation\TranslatorInterface;
1617

@@ -19,6 +20,9 @@
1920
*/
2021
class LegacyTranslatorProxy implements LegacyTranslatorInterface
2122
{
23+
use LegacyTranslatorTrait {
24+
transChoice as private doTransChoice;
25+
}
2226
private $translator;
2327

2428
public function __construct(TranslatorInterface $translator)
@@ -60,6 +64,10 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
6064
*/
6165
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
6266
{
63-
return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
67+
if ($this->translator instanceof LegacyTranslatorInterface) {
68+
return $this->translator->transChoice($id, $number, $parameters, $domain, $locale);
69+
}
70+
71+
$this->doTransChoice($id, $number, $parameters, $domain, $locale);
6472
}
6573
}

Violation/ConstraintViolationBuilder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Violation;
1313

14+
use Symfony\Component\Translation\TranslatorInterface as LegacyTranslatorInterface;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\ConstraintViolation;
1617
use Symfony\Component\Validator\ConstraintViolationList;
@@ -141,7 +142,7 @@ public function setCause($cause)
141142
*/
142143
public function addViolation()
143144
{
144-
if (null === $this->plural) {
145+
if (null === $this->plural || !$this->translator instanceof LegacyTranslatorInterface) {
145146
$translatedMessage = $this->translator->trans(
146147
$this->message,
147148
$this->parameters,

0 commit comments

Comments
 (0)