schmittjoh / JMSTranslationBundle

Puts the Symfony2 Translation Component on steroids
http://jmsyst.com/bundles/JMSTranslationBundle
426 stars 292 forks source link

All Form Constraint options are extracted without checking if it's a message or not #553

Closed nfragnet closed 3 years ago

nfragnet commented 3 years ago
Q A
Bundle version 1.5.x-dev (post 1.5.4)
Symfony version 5.2.0
PHP version 7.4.13

Expected behavior

Constraint messages extraction should only occur on translatable options.

Actual behavior

Since this commit https://github.com/schmittjoh/JMSTranslationBundle/commit/60d2d1384bfe2af590ed809f118777bba9007f97 where messages from constraints have been added, every options containing a string or even a integer value is extracted.

Steps to reproduce

Add this line in the tests and make the tests fail and execute phpunit.

diff --git a/Tests/Translation/Extractor/File/Fixture/MyFormType.php b/Tests/Translation/Extractor/File/Fixture/MyFormType.php
index cda5157..68139f0 100644
--- a/Tests/Translation/Extractor/File/Fixture/MyFormType.php
+++ b/Tests/Translation/Extractor/File/Fixture/MyFormType.php
@@ -46,6 +46,7 @@ class MyFormType extends AbstractType
                 'translation_domain' => 'address',
                 'constraints' => [
                     new NotBlank(['message' => /** @Desc("You should fill in the street") */ 'form.street.empty_value']),
+                    new Length(['max' => 100]),
                 ],
             ])

This should not result with an additional translation key "100" but it actually does.

             'messages' => Array (
                 'form.street.empty_value' => JMS\TranslationBundle\Model\Message Object (...)
                 'form.error.password_mismatch' => JMS\TranslationBundle\Model\Message Object (...)
+                100 => JMS\TranslationBundle\Model\Message Object (...)
             )
         )

I create a PR to fix it soon.