feat(translations/en): add English translations for requriedXXX and excludeXXX tags

Add English translations and tests for these tags:
 required_unless
 required_with
 required_with_all
 required_without
 required_without_all
 excluded_if
 excluded_unless
 excluded_with
 excluded_with_all
 excluded_without
 excluded_without_all
pull/987/head
violin0622 2 years ago
parent 9e2ea40380
commit 2d336e25a6
  1. BIN
      translations/en/.en.go.swp
  2. BIN
      translations/en/.en_test.go.swp
  3. 60
      translations/en/en.go
  4. 81
      translations/en/en_test.go

Binary file not shown.

Binary file not shown.

@ -33,6 +33,66 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0} is a required field",
override: false,
},
{
tag: "required_unless",
translation: "{0} is a required field",
override: false,
},
{
tag: "required_with",
translation: "{0} is a required field",
override: false,
},
{
tag: "required_with_all",
translation: "{0} is a required field",
override: false,
},
{
tag: "required_without",
translation: "{0} is a required field",
override: false,
},
{
tag: "required_without_all",
translation: "{0} is a required field",
override: false,
},
{
tag: "excluded_if",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "excluded_unless",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "excluded_with",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "excluded_with_all",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "excluded_without",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "excluded_without_all",
translation: "{0} is an excluded field",
override: false,
},
{
tag: "isdefault",
translation: "{0} must be default value",
override: false,
},
{
tag: "len",
customRegisFunc: func(ut ut.Translator) (err error) {

@ -28,6 +28,17 @@ func TestTranslations(t *testing.T) {
LtCSFieldString string
LteCSFieldString string
RequiredIf string
RequiredUnless string
RequiredWith string
RequiredWithAll string
RequiredWithout string
RequiredWithoutAll string
ExcludedIf string
ExcludedUnless string
ExcludedWith string
ExcludedWithAll string
ExcludedWithout string
ExcludedWithoutAll string
}
type Test struct {
@ -36,6 +47,18 @@ func TestTranslations(t *testing.T) {
RequiredNumber int `validate:"required"`
RequiredMultiple []string `validate:"required"`
RequiredIf string `validate:"required_if=Inner.RequiredIf abcd"`
RequiredUnless string `validate:"required_unless=Inner.RequiredUnless abcd"`
RequiredWith string `validate:"required_with=Inner.RequiredWith"`
RequiredWithAll string `validate:"required_with_all=Inner.RequiredWith Inner.RequiredWithAll"`
RequiredWithout string `validate:"required_without=Inner.RequiredWithout"`
RequiredWithoutAll string `validate:"required_without_all=Inner.RequiredWithout Inner.RequiredWithoutAll"`
ExcludedIf string `validate:"excluded_if=Inner.ExcludedIf abcd"`
ExcludedUnless string `validate:"excluded_unless=Inner.ExcludedUnless abcd"`
ExcludedWith string `validate:"excluded_with=Inner.ExcludedWith"`
ExcludedWithout string `validate:"excluded_with_all=Inner.ExcludedWithAll"`
ExcludedWithAll string `validate:"excluded_without=Inner.ExcludedWithout"`
ExcludedWithoutAll string `validate:"excluded_without_all=Inner.ExcludedWithoutAll"`
IsDefault string `validate:"isdefault"`
LenString string `validate:"len=1"`
LenNumber float64 `validate:"len=1113.00"`
LenMultiple []string `validate:"len=7"`
@ -159,6 +182,20 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "1234"
test.Inner.RequiredUnless = "1234"
test.Inner.RequiredWith = "1234"
test.Inner.RequiredWithAll = "1234"
test.Inner.ExcludedIf = "abcd"
test.Inner.ExcludedUnless = "1234"
test.Inner.ExcludedWith = "1234"
test.Inner.ExcludedWithAll = "1234"
test.ExcludedIf = "1234"
test.ExcludedUnless = "1234"
test.ExcludedWith = "1234"
test.ExcludedWithAll = "1234"
test.ExcludedWithout = "1234"
test.ExcludedWithoutAll = "1234"
test.MaxString = "1234"
test.MaxNumber = 2000
@ -610,6 +647,50 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple",
expected: "RequiredMultiple is a required field",
},
{
ns: "Test.RequiredUnless",
expected: "RequiredUnless is a required field",
},
{
ns: "Test.RequiredWith",
expected: "RequiredWith is a required field",
},
{
ns: "Test.RequiredWithAll",
expected: "RequiredWithAll is a required field",
},
{
ns: "Test.RequiredWithout",
expected: "RequiredWithout is a required field",
},
{
ns: "Test.RequiredWithoutAll",
expected: "RequiredWithoutAll is a required field",
},
{
ns: "Test.ExcludedIf",
expected: "ExcludedIf is an excluded field",
},
{
ns: "Test.ExcludedUnless",
expected: "ExcludedUnless is an excluded field",
},
{
ns: "Test.ExcludedWith",
expected: "ExcludedWith is an excluded field",
},
{
ns: "Test.ExcludedWithAll",
expected: "ExcludedWithAll is an excluded field",
},
{
ns: "Test.ExcludedWithout",
expected: "ExcludedWithout is an excluded field",
},
{
ns: "Test.ExcludedWithoutAll",
expected: "ExcludedWithoutAll is an excluded field",
},
{
ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen must be at least 10 characters in length",

Loading…
Cancel
Save