php-translation / extractor

Extracts translation strings from source code
MIT License
126 stars 33 forks source link

Validation translation domain should respect the Translator translationDomain #134

Open axi opened 4 years ago

axi commented 4 years ago

string "validators" translation domain should respect the Translator translationDomain witch can be modified through configuration (validator.translation_domain: my_custom_validation_translation_domain).

See in Translation\Extractor\Visitor\Php\Symfony\ValidationAnnotation

    /**
     * @param array $constraints
     */
    private function extractFromConstraints(array $constraints)
    {
        foreach ($constraints as $constraint) {
            $ref = new \ReflectionClass($constraint);
            $defaultValues = $ref->getDefaultProperties();

            $properties = $ref->getProperties();

            foreach ($properties as $property) {
                $propName = $property->getName();

                // If the property ends with 'Message'
                if ('message' === strtolower(substr($propName, -1 * strlen('Message')))) {
                    // If it is different from the default value
                    if ($defaultValues[$propName] !== $constraint->{$propName}) {
                        $this->addLocation($constraint->{$propName}, 0, null, ['domain' => 'validators']);
                    }
                }
            }
        }
    }

Not sure of the best way to do this, any idea ?