Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #697 - add missing "en" translations for "required" tags #884

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions translations/en/en.go
Expand Up @@ -28,6 +28,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0} is a required field",
override: false,
},
{
tag: "required_if",
translation: "{0} is a required field",
override: false,
},
{
tag: "len",
customRegisFunc: func(ut ut.Translator) (err error) {
Expand Down
8 changes: 8 additions & 0 deletions translations/en/en_test.go
Expand Up @@ -27,13 +27,15 @@ func TestTranslations(t *testing.T) {
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
RequiredIf string
}

type Test struct {
Inner Inner
RequiredString string `validate:"required"`
RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"`
Expand Down Expand Up @@ -202,6 +204,8 @@ func TestTranslations(t *testing.T) {
test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"}
test.Datetime = "2008-Feb-01"

test.Inner.RequiredIf = "abcd"

err = validate.Struct(test)
NotEqual(t, err, nil)

Expand Down Expand Up @@ -592,6 +596,10 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredString",
expected: "RequiredString is a required field",
},
{
ns: "Test.RequiredIf",
expected: "RequiredIf is a required field",
},
{
ns: "Test.RequiredNumber",
expected: "RequiredNumber is a required field",
Expand Down