@@ -33,13 +33,13 @@ class ConstraintViolationBuilder implements ConstraintViolationBuilderInterface
33
33
private mixed $ invalidValue ;
34
34
private string $ propertyPath ;
35
35
private TranslatorInterface $ translator ;
36
- private ? string $ translationDomain ;
36
+ private string | false | null $ translationDomain ;
37
37
private ?int $ plural = null ;
38
38
private ?Constraint $ constraint ;
39
39
private ?string $ code = null ;
40
40
private mixed $ cause = null ;
41
41
42
- public function __construct (ConstraintViolationList $ violations , ?Constraint $ constraint , string |\Stringable $ message , array $ parameters , mixed $ root , ?string $ propertyPath , mixed $ invalidValue , TranslatorInterface $ translator , string $ translationDomain = null )
42
+ public function __construct (ConstraintViolationList $ violations , ?Constraint $ constraint , string |\Stringable $ message , array $ parameters , mixed $ root , ?string $ propertyPath , mixed $ invalidValue , TranslatorInterface $ translator , string | false $ translationDomain = null )
43
43
{
44
44
$ this ->violations = $ violations ;
45
45
$ this ->message = $ message ;
@@ -80,6 +80,16 @@ public function setTranslationDomain(string $translationDomain): static
80
80
return $ this ;
81
81
}
82
82
83
+ /**
84
+ * @return $this
85
+ */
86
+ public function disableTranslation (): static
87
+ {
88
+ $ this ->translationDomain = false ;
89
+
90
+ return $ this ;
91
+ }
92
+
83
93
public function setInvalidValue (mixed $ invalidValue ): static
84
94
{
85
95
$ this ->invalidValue = $ invalidValue ;
@@ -110,16 +120,13 @@ public function setCause(mixed $cause): static
110
120
111
121
public function addViolation (): void
112
122
{
113
- if (null === $ this ->plural ) {
114
- $ translatedMessage = $ this ->translator ->trans (
115
- $ this ->message ,
116
- $ this ->parameters ,
117
- $ this ->translationDomain
118
- );
123
+ $ parameters = null === $ this ->plural ? $ this ->parameters : (['%count% ' => $ this ->plural ] + $ this ->parameters );
124
+ if (false === $ this ->translationDomain ) {
125
+ $ translatedMessage = strtr ($ this ->message , $ parameters );
119
126
} else {
120
127
$ translatedMessage = $ this ->translator ->trans (
121
128
$ this ->message ,
122
- [ ' %count% ' => $ this -> plural ] + $ this -> parameters ,
129
+ $ parameters ,
123
130
$ this ->translationDomain
124
131
);
125
132
}
0 commit comments