Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean translation #930

Merged
merged 2 commits into from May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions translations/en/en.go
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions translations/en/en_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions translations/pt_BR/pt_BR.go
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions translations/pt_BR/pt_BR_test.go
Expand Up @@ -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
Expand Down Expand Up @@ -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!"
Expand Down Expand Up @@ -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 {
Expand Down