Skip to content

feat: validation error messages should use the framework translation …#1436

Open
h2zi wants to merge 3 commits intomasterfrom
haozi/validation
Open

feat: validation error messages should use the framework translation …#1436
h2zi wants to merge 3 commits intomasterfrom
haozi/validation

Conversation

@h2zi
Copy link
Copy Markdown
Contributor

@h2zi h2zi commented Apr 8, 2026

…module

📑 Description

Closes goravel/goravel#939

@coderabbitai summary

✅ Checks

  • Added test cases for my code

Copilot AI review requested due to automatic review settings April 8, 2026 20:50
@h2zi h2zi requested a review from a team as a code owner April 8, 2026 20:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Translator into the validation engine and resolve messages via validation.* translation keys (with size-rule type variants).
  • Replace the large in-code defaultMessages map with an embedded lang/en/validation.json that 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
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

❌ Patch coverage is 81.81818% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.80%. Comparing base (55ee67d) to head (288e4e2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
validation/lang.go 80.95% 2 Missing and 2 partials ⚠️
validation/service_provider.go 20.00% 4 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@hwbrzzl hwbrzzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +42 to +44
app.Publishes("github.com/goravel/framework/validation", map[string]string{
"lang": app.LangPath(),
}, "goravel-validation-lang")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may find a more graceful way to publish the lang files instead of github.com/goravel/framework/validation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. What package name would you prefer? Something like goravel/validation or a tag-only approach?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding a new lang:publish command like https://laravel.com/docs/13.x/validation#quick-customizing-the-error-messages?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be implemented in another PR if you want.

Copilot AI review requested due to automatic review settings April 9, 2026 10:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation error messages should use the framework translation module

3 participants