Improve ValidationError translation extraction#735
Draft
mikadamczyk wants to merge 1 commit intomainfrom
Draft
Conversation
720516c to
beffe9e
Compare
beffe9e to
ec7c03b
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description:
This PR improves the way translation messages are extracted from
ValidationErrorusages.Until now, the custom ValidationErrorFileVisitor only accepted scalar string literals as translation IDs. In practice, this meant that a very common and perfectly valid PHP pattern, such as
new ValidationError(self::SOME_MESSAGE), could not be extracted, even though the value was statically known. As a result, developers had to either inline translation keys as raw strings, duplicate messages elsewhere for extraction purposes, or silence the extractor with@Ignore.This change makes the extractor more practical and consistent with real-world usage.
ValidationErrorFileVisitornow supports simple class constant references, including self::CONST, static::CONST, and equivalent references to the current class, as long as they can be resolved statically to a string value. The implementation intentionally stays conservative: it does not try to evaluate arbitrary PHP expressions, and it only resolves cases that are safe and predictable during AST-based analysis.In addition, this PR introduces support for a new
@Domain(...)annotation for ValidationError extraction. Previously, messages handled byValidationErrorFileVisitoralways fell back to the visitor’s default domain, which made it impossible to cleanly route validation messages into domains such as validators without relying on separate translation container declarations. With@Domain(...), the extraction domain can now be controlled directly at the ValidationError call site, alongside existing metadata such as@Descand@Meaning.The runtime JMS doc parser configuration has also been updated so that the new annotation is recognized during actual translation extraction, not only in isolated unit tests. This was necessary to make the feature work end-to-end in real extraction runs.
The test suite for ValidationErrorFileVisitor has been expanded accordingly. It now covers extraction from string literals, extraction from class constants, imported
@Descusage, and explicit domain override with@Domain(...). The visitor implementation was also slightly tightened to satisfy static analysis more cleanly.While working on extraction issues, a few remaining ValidationError usages were identified where the translation ID is still passed through a variable. Those cases are not meaningfully extractable with the current static model and were already effectively unsupported. For now, they have been marked with
@Ignoreand documented with TODO comments explaining that they shouldeventually be refactored to stable translation keys or templates. This keeps extraction noise down without pretending those messages are currently extractable.
For QA:
Documentation: