Skip to content

Commit

Permalink
fix: add en translation for required_if (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
renato0307 committed May 1, 2022
1 parent 0a26ee5 commit d37da5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit d37da5e

Please sign in to comment.