feat: validation-error i18n contract (deferred-translation)#11
Merged
Conversation
…atableMessage union
… drop in-request translation
…on the wire
BREAKING CHANGE: MiddagValidationException::errors() values and the 422
errors[field] payload change from string|string[] to an object
{message,key,domain,params} (a list when a field has several errors).
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.
Summary
Deferred-translation contract for validation errors.
MiddagValidationException::errors()now carries a framework-ownedTranslatableMessage({key, domain, params, defaultMessage}, mirroring Symfony'sTranslatableMessage+ a Spring-styledefaultMessage).HttpKernelresolves each error at the response boundary to the wire shape{message, key, domain, params}(RFC 9457 / SymfonyConstraintViolationListNormalizeraligned):messageis resolved through the bound host translator, falling back to English. Hosts (Moodleget_string, WordPress__) and React/Inertia clients localise viakey/params; standalone is English by default.Also fixes a bug:
DtoHydratorno longer hardcodes'This value is not valid.'for denormalization errors — it routes through the translator with a stable key.New
TranslatableMessage,ViolationKeyMap,ValidationErrorBag,ValidationErrorSerializer. Validation no longer translates in-request; the kernel is the single resolution boundary.Breaking
MiddagValidationException::errors()values and the 422errors[field]payload change fromstring|string[]to{message, key, domain, params}(a list when a field has several errors). Raw-string errors still pass through unchanged. Pre-1.0 → minor (0.11.0).Gate
composer check(PHPStan L6 + PHP-CS-Fixer + Rector) +composer test(545 tests) green; CI green on PHP 8.2 / 8.3 / 8.4.