From d37da5e53c4b42b70227b383814692133a5f738f Mon Sep 17 00:00:00 2001 From: Renato Alves Torres Date: Sun, 1 May 2022 16:50:01 +0100 Subject: [PATCH] fix: add en translation for required_if (#884) --- translations/en/en.go | 5 +++++ translations/en/en_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/translations/en/en.go b/translations/en/en.go index 5ed76ae..5784d1f 100644 --- a/translations/en/en.go +++ b/translations/en/en.go @@ -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) { diff --git a/translations/en/en_test.go b/translations/en/en_test.go index 146c475..4c1d605 100644 --- a/translations/en/en_test.go +++ b/translations/en/en_test.go @@ -27,6 +27,7 @@ func TestTranslations(t *testing.T) { GteCSFieldString string LtCSFieldString string LteCSFieldString string + RequiredIf string } type Test struct { @@ -34,6 +35,7 @@ func TestTranslations(t *testing.T) { 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"` @@ -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) @@ -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",