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 98ce3f0

Browse filesBrowse files
alexandre-dauboisfabpot
authored andcommitted
[FrameworkBundle][Validator] Add framework.validation.disable_translation config
1 parent e50af3d commit 98ce3f0
Copy full SHA for 98ce3f0

File tree

9 files changed

+31
-4
lines changed
Filter options

9 files changed

+31
-4
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CHANGELOG
1010
* Add new `framework.property_info.with_constructor_extractor` option to allow enabling or disabling the constructor extractor integration
1111
* Deprecate the `--show-arguments` option of the `container:debug` command, as arguments are now always shown
1212
* Add `RateLimiterFactoryInterface` as an alias of the `limiter` service
13+
* Add `framework.validation.disable_translation` option
1314

1415
7.2
1516
---

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,9 @@ private function addValidationSection(ArrayNodeDefinition $rootNode, callable $e
10621062
->end()
10631063
->end()
10641064
->end()
1065+
->booleanNode('disable_translation')
1066+
->defaultFalse()
1067+
->end()
10651068
->arrayNode('auto_mapping')
10661069
->info('A collection of namespaces for which auto-mapping will be enabled by default, or null to opt-in with the EnableAutoMapping constraint.')
10671070
->example([

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,6 +1724,10 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
17241724
$validatorBuilder->addMethodCall('setMappingCache', [new Reference('validator.mapping.cache.adapter')]);
17251725
}
17261726

1727+
if ($config['disable_translation'] ?? false) {
1728+
$validatorBuilder->addMethodCall('disableTranslation');
1729+
}
1730+
17271731
$container->setParameter('validator.auto_mapping', $config['auto_mapping']);
17281732
if (!$propertyInfoEnabled || !class_exists(PropertyInfoLoader::class)) {
17291733
$container->removeDefinition('validator.property_info_loader');

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@
298298
<xsd:attribute name="enable-attributes" type="xsd:boolean" />
299299
<xsd:attribute name="static-method" type="xsd:boolean" />
300300
<xsd:attribute name="translation-domain" type="xsd:string" />
301+
<xsd:attribute name="disable-translation" type="xsd:boolean" />
301302
<xsd:attribute name="strict-email" type="xsd:boolean" />
302303
<xsd:attribute name="email-validation-mode" type="email-validation-mode" />
303304
</xsd:complexType>

‎src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ protected static function getBundleDefaultConfig()
775775
'enable_attributes' => !class_exists(FullStack::class),
776776
'static_method' => ['loadValidatorMetadata'],
777777
'translation_domain' => 'validators',
778+
'disable_translation' => false,
778779
'mapping' => [
779780
'paths' => [],
780781
],

‎src/Symfony/Component/Validator/Context/ExecutionContext.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Context/ExecutionContext.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(
107107
private ValidatorInterface $validator,
108108
private mixed $root,
109109
private TranslatorInterface $translator,
110-
private ?string $translationDomain = null,
110+
private string|false|null $translationDomain = null,
111111
) {
112112
$this->violations = new ConstraintViolationList();
113113
$this->cachedObjectsRefs = new \SplObjectStorage();
@@ -134,7 +134,9 @@ public function setConstraint(Constraint $constraint): void
134134
public function addViolation(string|\Stringable $message, array $parameters = []): void
135135
{
136136
$this->violations->add(new ConstraintViolation(
137-
$this->translator->trans($message, $parameters, $this->translationDomain),
137+
false === $this->translationDomain ?
138+
strtr($message, $parameters) :
139+
$this->translator->trans($message, $parameters, $this->translationDomain),
138140
$message,
139141
$parameters,
140142
$this->root,

‎src/Symfony/Component/Validator/Context/ExecutionContextFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Context/ExecutionContextFactory.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ExecutionContextFactory implements ExecutionContextFactoryInterface
2525
{
2626
public function __construct(
2727
private TranslatorInterface $translator,
28-
private ?string $translationDomain = null,
28+
private string|false|null $translationDomain = null,
2929
) {
3030
}
3131

‎src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/ValidatorBuilderTest.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function testSetTranslationDomain()
9999
$this->assertSame($this->builder, $this->builder->setTranslationDomain('TRANS_DOMAIN'));
100100
}
101101

102+
public function testDisableTranslation()
103+
{
104+
$this->assertSame($this->builder, $this->builder->disableTranslation());
105+
}
106+
102107
public function testGetValidator()
103108
{
104109
$this->assertInstanceOf(RecursiveValidator::class, $this->builder->getValidator());

‎src/Symfony/Component/Validator/ValidatorBuilder.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/ValidatorBuilder.php
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ValidatorBuilder
5050
private ?ContainerInterface $groupProviderLocator = null;
5151
private ?CacheItemPoolInterface $mappingCache = null;
5252
private ?TranslatorInterface $translator = null;
53-
private ?string $translationDomain = null;
53+
private string|false|null $translationDomain = null;
5454

5555
/**
5656
* Adds an object initializer to the validator.
@@ -292,6 +292,16 @@ public function setTranslationDomain(?string $translationDomain): static
292292
return $this;
293293
}
294294

295+
/**
296+
* @return $this
297+
*/
298+
public function disableTranslation(): static
299+
{
300+
$this->translationDomain = false;
301+
302+
return $this;
303+
}
304+
295305
/**
296306
* @return $this
297307
*/

0 commit comments

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