feat: validation error messages should use the framework translation …#1436
feat: validation error messages should use the framework translation …#1436
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the validation module to source default validation error messages from the framework translation system (Lang) instead of hard-coded strings, aligning validation errors with localized translations and making language assets publishable.
Changes:
- Pass a framework
Translatorinto the validation engine and resolve messages viavalidation.*translation keys (with size-rule type variants). - Replace the large in-code
defaultMessagesmap with an embeddedlang/en/validation.jsonthat is flattened at init time for fallback behavior. - Add vendor publish support for the validation language files and extend unit tests for translation precedence and new custom-rule placeholders.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| validation/validation.go | Injects the translator into NewEngine via langFacade(ctx) during Make. |
| validation/service_provider.go | Wires MakeLang into langFacade and publishes lang/ assets under a new publish tag. |
| validation/messages.go | Updates getMessage to prefer translations before default fallbacks; adjusts signature to accept a translator. |
| validation/messages_test.go | Adds tests for translation precedence and fallback behavior. |
| validation/lang/en/validation.json | Adds the default English validation messages as translation assets. |
| validation/lang.go | Embeds lang/ and initializes defaultMessages by flattening the JSON. |
| validation/engine.go | Threads translator through Engine, and adds :value / :optionN placeholders for custom rules. |
| validation/engine_test.go | Updates tests for new formatErrorMessage signature and adds placeholder coverage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1436 +/- ##
==========================================
+ Coverage 68.76% 68.80% +0.04%
==========================================
Files 361 362 +1
Lines 27776 27869 +93
==========================================
+ Hits 19099 19175 +76
- Misses 7831 7845 +14
- Partials 846 849 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| app.Publishes("github.com/goravel/framework/validation", map[string]string{ | ||
| "lang": app.LangPath(), | ||
| }, "goravel-validation-lang") |
There was a problem hiding this comment.
We may find a more graceful way to publish the lang files instead of github.com/goravel/framework/validation
There was a problem hiding this comment.
Agreed. What package name would you prefer? Something like goravel/validation or a tag-only approach?
There was a problem hiding this comment.
How about adding a new lang:publish command like https://laravel.com/docs/13.x/validation#quick-customizing-the-error-messages?
There was a problem hiding this comment.
It can be implemented in another PR if you want.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…module
📑 Description
Closes goravel/goravel#939
@coderabbitai summary
✅ Checks