From 5daaeb2e5f1edf1889e5e3580b535e1f35be38aa Mon Sep 17 00:00:00 2001 From: Eduardo Mello Date: Tue, 5 Apr 2022 11:21:55 -0300 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20add=20en=20boolean=20translatio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translations/en/en.go | 5 +++++ translations/en/en_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/translations/en/en.go b/translations/en/en.go index 5ed76aea..1c0543c8 100644 --- a/translations/en/en.go +++ b/translations/en/en.go @@ -1346,6 +1346,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er return t }, }, + { + tag: "boolean", + translation: "{0} must be a valid boolean value", + override: false, + }, } for _, t := range translations { diff --git a/translations/en/en_test.go b/translations/en/en_test.go index 146c475e..c778b079 100644 --- a/translations/en/en_test.go +++ b/translations/en/en_test.go @@ -149,6 +149,7 @@ func TestTranslations(t *testing.T) { PostCode string `validate:"postcode_iso3166_alpha2=SG"` PostCodeCountry string PostCodeByField string `validate:"postcode_iso3166_alpha2_field=PostCodeCountry"` + BooleanString string `validate:"boolean"` } var test Test @@ -201,6 +202,7 @@ func TestTranslations(t *testing.T) { test.UniqueSlice = []string{"1234", "1234"} test.UniqueMap = map[string]string{"key1": "1234", "key2": "1234"} test.Datetime = "2008-Feb-01" + test.BooleanString = "A" err = validate.Struct(test) NotEqual(t, err, nil) @@ -676,6 +678,10 @@ func TestTranslations(t *testing.T) { ns: "Test.PostCodeByField", expected: "PostCodeByField does not match postcode format of country in PostCodeCountry field", }, + { + ns: "Test.BooleanString", + expected: "BooleanString must be a valid boolean value", + }, } for _, tt := range tests { From d8c360ddb494798a67eba9811cafa32ac7739858 Mon Sep 17 00:00:00 2001 From: Eduardo Mello Date: Tue, 5 Apr 2022 11:22:05 -0300 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20add=20pt-BR=20boolean=20transla?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- translations/pt_BR/pt_BR.go | 5 +++++ translations/pt_BR/pt_BR_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/translations/pt_BR/pt_BR.go b/translations/pt_BR/pt_BR.go index ef044963..d6883aa9 100644 --- a/translations/pt_BR/pt_BR.go +++ b/translations/pt_BR/pt_BR.go @@ -1316,6 +1316,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er return s }, }, + { + tag: "boolean", + translation: "{0} deve ser um valor booleano válido", + override: false, + }, } for _, t := range translations { diff --git a/translations/pt_BR/pt_BR_test.go b/translations/pt_BR/pt_BR_test.go index c8a64826..426f2468 100644 --- a/translations/pt_BR/pt_BR_test.go +++ b/translations/pt_BR/pt_BR_test.go @@ -139,6 +139,7 @@ func TestTranslations(t *testing.T) { StrPtrGte *string `validate:"gte=10"` OneOfString string `validate:"oneof=red green"` OneOfInt int `validate:"oneof=5 63"` + BooleanString string `validate:"boolean"` } var test Test @@ -171,6 +172,7 @@ func TestTranslations(t *testing.T) { test.AlphanumString = "abc3!" test.NumericString = "12E.00" test.NumberString = "12E" + test.BooleanString = "A" test.Excludes = "este é um texto de teste" test.ExcludesAll = "Isso é Ótimo!" @@ -619,6 +621,10 @@ func TestTranslations(t *testing.T) { ns: "Test.OneOfInt", expected: "OneOfInt deve ser um de [5 63]", }, + { + ns: "Test.BooleanString", + expected: "BooleanString deve ser um valor booleano válido", + }, } for _, tt := range tests {