#updated Added required_without spanish translation

pull/1099/head
Roberto Ramírez N 2 years ago
parent f5e5146b31
commit 44fffe1062
  1. 15
      translations/es/es.go
  2. 18
      translations/es/es_test.go

@ -34,6 +34,21 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0} es un campo requerido", translation: "{0} es un campo requerido",
override: false, 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", tag: "len",
customRegisFunc: func(ut ut.Translator) (err error) { customRegisFunc: func(ut ut.Translator) (err error) {

@ -22,12 +22,13 @@ func TestTranslations(t *testing.T) {
Equal(t, err, nil) Equal(t, err, nil)
type Inner struct { type Inner struct {
EqCSFieldString string EqCSFieldString string
NeCSFieldString string NeCSFieldString string
GtCSFieldString string GtCSFieldString string
GteCSFieldString string GteCSFieldString string
LtCSFieldString string LtCSFieldString string
LteCSFieldString string LteCSFieldString string
RequiredWithoutField string
} }
type Test struct { type Test struct {
@ -36,6 +37,7 @@ func TestTranslations(t *testing.T) {
RequiredNumber int `validate:"required"` RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"` RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"` RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
RequiredWithout string `validate:"required_without=Inner.RequiredWithoutField"`
LenString string `validate:"len=1"` LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"` LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"` LenMultiple []string `validate:"len=7"`
@ -638,6 +640,10 @@ func TestTranslations(t *testing.T) {
ns: "Test.UniqueMap", ns: "Test.UniqueMap",
expected: "UniqueMap debe contener valores únicos", 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 { for _, tt := range tests {

Loading…
Cancel
Save