From 44fffe10626778b95c36219da8fde93d1e8fd2ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Ram=C3=ADrez=20N?= Date: Fri, 21 Apr 2023 19:37:18 -0600 Subject: [PATCH] #updated Added required_without spanish translation --- translations/es/es.go | 15 +++++++++++++++ translations/es/es_test.go | 18 ++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/translations/es/es.go b/translations/es/es.go index 73b06cf..432daa6 100644 --- a/translations/es/es.go +++ b/translations/es/es.go @@ -34,6 +34,21 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er translation: "{0} es un campo requerido", override: false, }, + { + tag: "required_without", + translation: "{0} es un campo requerido cuando los campos [{1}] no estan presentes", + customTransFunc: func(ut ut.Translator, fe validator.FieldError) string { + + t, err := ut.T(fe.Tag(), fe.Field(), fe.Param()) + if err != nil { + fmt.Printf("warning: error translating FieldError: %#v", fe) + return fe.(error).Error() + } + + return t + }, + override: false, + }, { tag: "len", customRegisFunc: func(ut ut.Translator) (err error) { diff --git a/translations/es/es_test.go b/translations/es/es_test.go index c2c4c81..3489e73 100644 --- a/translations/es/es_test.go +++ b/translations/es/es_test.go @@ -22,12 +22,13 @@ func TestTranslations(t *testing.T) { Equal(t, err, nil) type Inner struct { - EqCSFieldString string - NeCSFieldString string - GtCSFieldString string - GteCSFieldString string - LtCSFieldString string - LteCSFieldString string + EqCSFieldString string + NeCSFieldString string + GtCSFieldString string + GteCSFieldString string + LtCSFieldString string + LteCSFieldString string + RequiredWithoutField string } type Test struct { @@ -36,6 +37,7 @@ func TestTranslations(t *testing.T) { RequiredNumber int `validate:"required"` RequiredMultiple []string `validate:"required"` RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"` + RequiredWithout string `validate:"required_without=Inner.RequiredWithoutField"` LenString string `validate:"len=1"` LenNumber float64 `validate:"len=1113.00"` LenMultiple []string `validate:"len=7"` @@ -638,6 +640,10 @@ func TestTranslations(t *testing.T) { ns: "Test.UniqueMap", expected: "UniqueMap debe contener valores Ășnicos", }, + { + ns: "Test.RequiredWithout", + expected: "RequiredWithout es un campo requerido cuando los campos [Inner.RequiredWithoutField] no estan presentes", + }, } for _, tt := range tests {