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. 337
      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", translation: "{0} is a required field",
override: false, 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", tag: "len",
customRegisFunc: func(ut ut.Translator) (err error) { customRegisFunc: func(ut ut.Translator) (err error) {

@ -21,137 +21,160 @@ 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
RequiredIf 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 { type Test struct {
Inner Inner Inner Inner
RequiredString string `validate:"required"` RequiredString string `validate:"required"`
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"`
LenString string `validate:"len=1"` RequiredUnless string `validate:"required_unless=Inner.RequiredUnless abcd"`
LenNumber float64 `validate:"len=1113.00"` RequiredWith string `validate:"required_with=Inner.RequiredWith"`
LenMultiple []string `validate:"len=7"` RequiredWithAll string `validate:"required_with_all=Inner.RequiredWith Inner.RequiredWithAll"`
MinString string `validate:"min=1"` RequiredWithout string `validate:"required_without=Inner.RequiredWithout"`
MinNumber float64 `validate:"min=1113.00"` RequiredWithoutAll string `validate:"required_without_all=Inner.RequiredWithout Inner.RequiredWithoutAll"`
MinMultiple []string `validate:"min=7"` ExcludedIf string `validate:"excluded_if=Inner.ExcludedIf abcd"`
MaxString string `validate:"max=3"` ExcludedUnless string `validate:"excluded_unless=Inner.ExcludedUnless abcd"`
MaxNumber float64 `validate:"max=1113.00"` ExcludedWith string `validate:"excluded_with=Inner.ExcludedWith"`
MaxMultiple []string `validate:"max=7"` ExcludedWithout string `validate:"excluded_with_all=Inner.ExcludedWithAll"`
EqString string `validate:"eq=3"` ExcludedWithAll string `validate:"excluded_without=Inner.ExcludedWithout"`
EqNumber float64 `validate:"eq=2.33"` ExcludedWithoutAll string `validate:"excluded_without_all=Inner.ExcludedWithoutAll"`
EqMultiple []string `validate:"eq=7"` IsDefault string `validate:"isdefault"`
NeString string `validate:"ne="` LenString string `validate:"len=1"`
NeNumber float64 `validate:"ne=0.00"` LenNumber float64 `validate:"len=1113.00"`
NeMultiple []string `validate:"ne=0"` LenMultiple []string `validate:"len=7"`
LtString string `validate:"lt=3"` MinString string `validate:"min=1"`
LtNumber float64 `validate:"lt=5.56"` MinNumber float64 `validate:"min=1113.00"`
LtMultiple []string `validate:"lt=2"` MinMultiple []string `validate:"min=7"`
LtTime time.Time `validate:"lt"` MaxString string `validate:"max=3"`
LteString string `validate:"lte=3"` MaxNumber float64 `validate:"max=1113.00"`
LteNumber float64 `validate:"lte=5.56"` MaxMultiple []string `validate:"max=7"`
LteMultiple []string `validate:"lte=2"` EqString string `validate:"eq=3"`
LteTime time.Time `validate:"lte"` EqNumber float64 `validate:"eq=2.33"`
GtString string `validate:"gt=3"` EqMultiple []string `validate:"eq=7"`
GtNumber float64 `validate:"gt=5.56"` NeString string `validate:"ne="`
GtMultiple []string `validate:"gt=2"` NeNumber float64 `validate:"ne=0.00"`
GtTime time.Time `validate:"gt"` NeMultiple []string `validate:"ne=0"`
GteString string `validate:"gte=3"` LtString string `validate:"lt=3"`
GteNumber float64 `validate:"gte=5.56"` LtNumber float64 `validate:"lt=5.56"`
GteMultiple []string `validate:"gte=2"` LtMultiple []string `validate:"lt=2"`
GteTime time.Time `validate:"gte"` LtTime time.Time `validate:"lt"`
EqFieldString string `validate:"eqfield=MaxString"` LteString string `validate:"lte=3"`
EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"` LteNumber float64 `validate:"lte=5.56"`
NeCSFieldString string `validate:"necsfield=Inner.NeCSFieldString"` LteMultiple []string `validate:"lte=2"`
GtCSFieldString string `validate:"gtcsfield=Inner.GtCSFieldString"` LteTime time.Time `validate:"lte"`
GteCSFieldString string `validate:"gtecsfield=Inner.GteCSFieldString"` GtString string `validate:"gt=3"`
LtCSFieldString string `validate:"ltcsfield=Inner.LtCSFieldString"` GtNumber float64 `validate:"gt=5.56"`
LteCSFieldString string `validate:"ltecsfield=Inner.LteCSFieldString"` GtMultiple []string `validate:"gt=2"`
NeFieldString string `validate:"nefield=EqFieldString"` GtTime time.Time `validate:"gt"`
GtFieldString string `validate:"gtfield=MaxString"` GteString string `validate:"gte=3"`
GteFieldString string `validate:"gtefield=MaxString"` GteNumber float64 `validate:"gte=5.56"`
LtFieldString string `validate:"ltfield=MaxString"` GteMultiple []string `validate:"gte=2"`
LteFieldString string `validate:"ltefield=MaxString"` GteTime time.Time `validate:"gte"`
AlphaString string `validate:"alpha"` EqFieldString string `validate:"eqfield=MaxString"`
AlphanumString string `validate:"alphanum"` EqCSFieldString string `validate:"eqcsfield=Inner.EqCSFieldString"`
NumericString string `validate:"numeric"` NeCSFieldString string `validate:"necsfield=Inner.NeCSFieldString"`
NumberString string `validate:"number"` GtCSFieldString string `validate:"gtcsfield=Inner.GtCSFieldString"`
HexadecimalString string `validate:"hexadecimal"` GteCSFieldString string `validate:"gtecsfield=Inner.GteCSFieldString"`
HexColorString string `validate:"hexcolor"` LtCSFieldString string `validate:"ltcsfield=Inner.LtCSFieldString"`
RGBColorString string `validate:"rgb"` LteCSFieldString string `validate:"ltecsfield=Inner.LteCSFieldString"`
RGBAColorString string `validate:"rgba"` NeFieldString string `validate:"nefield=EqFieldString"`
HSLColorString string `validate:"hsl"` GtFieldString string `validate:"gtfield=MaxString"`
HSLAColorString string `validate:"hsla"` GteFieldString string `validate:"gtefield=MaxString"`
Email string `validate:"email"` LtFieldString string `validate:"ltfield=MaxString"`
URL string `validate:"url"` LteFieldString string `validate:"ltefield=MaxString"`
URI string `validate:"uri"` AlphaString string `validate:"alpha"`
Base64 string `validate:"base64"` AlphanumString string `validate:"alphanum"`
Contains string `validate:"contains=purpose"` NumericString string `validate:"numeric"`
ContainsAny string `validate:"containsany=!@#$"` NumberString string `validate:"number"`
Excludes string `validate:"excludes=text"` HexadecimalString string `validate:"hexadecimal"`
ExcludesAll string `validate:"excludesall=!@#$"` HexColorString string `validate:"hexcolor"`
ExcludesRune string `validate:"excludesrune=☻"` RGBColorString string `validate:"rgb"`
ISBN string `validate:"isbn"` RGBAColorString string `validate:"rgba"`
ISBN10 string `validate:"isbn10"` HSLColorString string `validate:"hsl"`
ISBN13 string `validate:"isbn13"` HSLAColorString string `validate:"hsla"`
UUID string `validate:"uuid"` Email string `validate:"email"`
UUID3 string `validate:"uuid3"` URL string `validate:"url"`
UUID4 string `validate:"uuid4"` URI string `validate:"uri"`
UUID5 string `validate:"uuid5"` Base64 string `validate:"base64"`
ULID string `validate:"ulid"` Contains string `validate:"contains=purpose"`
ASCII string `validate:"ascii"` ContainsAny string `validate:"containsany=!@#$"`
PrintableASCII string `validate:"printascii"` Excludes string `validate:"excludes=text"`
MultiByte string `validate:"multibyte"` ExcludesAll string `validate:"excludesall=!@#$"`
DataURI string `validate:"datauri"` ExcludesRune string `validate:"excludesrune=☻"`
Latitude string `validate:"latitude"` ISBN string `validate:"isbn"`
Longitude string `validate:"longitude"` ISBN10 string `validate:"isbn10"`
SSN string `validate:"ssn"` ISBN13 string `validate:"isbn13"`
IP string `validate:"ip"` UUID string `validate:"uuid"`
IPv4 string `validate:"ipv4"` UUID3 string `validate:"uuid3"`
IPv6 string `validate:"ipv6"` UUID4 string `validate:"uuid4"`
CIDR string `validate:"cidr"` UUID5 string `validate:"uuid5"`
CIDRv4 string `validate:"cidrv4"` ULID string `validate:"ulid"`
CIDRv6 string `validate:"cidrv6"` ASCII string `validate:"ascii"`
TCPAddr string `validate:"tcp_addr"` PrintableASCII string `validate:"printascii"`
TCPAddrv4 string `validate:"tcp4_addr"` MultiByte string `validate:"multibyte"`
TCPAddrv6 string `validate:"tcp6_addr"` DataURI string `validate:"datauri"`
UDPAddr string `validate:"udp_addr"` Latitude string `validate:"latitude"`
UDPAddrv4 string `validate:"udp4_addr"` Longitude string `validate:"longitude"`
UDPAddrv6 string `validate:"udp6_addr"` SSN string `validate:"ssn"`
IPAddr string `validate:"ip_addr"` IP string `validate:"ip"`
IPAddrv4 string `validate:"ip4_addr"` IPv4 string `validate:"ipv4"`
IPAddrv6 string `validate:"ip6_addr"` IPv6 string `validate:"ipv6"`
UinxAddr string `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future CIDR string `validate:"cidr"`
MAC string `validate:"mac"` CIDRv4 string `validate:"cidrv4"`
IsColor string `validate:"iscolor"` CIDRv6 string `validate:"cidrv6"`
StrPtrMinLen *string `validate:"min=10"` TCPAddr string `validate:"tcp_addr"`
StrPtrMaxLen *string `validate:"max=1"` TCPAddrv4 string `validate:"tcp4_addr"`
StrPtrLen *string `validate:"len=2"` TCPAddrv6 string `validate:"tcp6_addr"`
StrPtrLt *string `validate:"lt=1"` UDPAddr string `validate:"udp_addr"`
StrPtrLte *string `validate:"lte=1"` UDPAddrv4 string `validate:"udp4_addr"`
StrPtrGt *string `validate:"gt=10"` UDPAddrv6 string `validate:"udp6_addr"`
StrPtrGte *string `validate:"gte=10"` IPAddr string `validate:"ip_addr"`
OneOfString string `validate:"oneof=red green"` IPAddrv4 string `validate:"ip4_addr"`
OneOfInt int `validate:"oneof=5 63"` IPAddrv6 string `validate:"ip6_addr"`
UniqueSlice []string `validate:"unique"` UinxAddr string `validate:"unix_addr"` // can't fail from within Go's net package currently, but maybe in the future
UniqueArray [3]string `validate:"unique"` MAC string `validate:"mac"`
UniqueMap map[string]string `validate:"unique"` IsColor string `validate:"iscolor"`
JSONString string `validate:"json"` StrPtrMinLen *string `validate:"min=10"`
JWTString string `validate:"jwt"` StrPtrMaxLen *string `validate:"max=1"`
LowercaseString string `validate:"lowercase"` StrPtrLen *string `validate:"len=2"`
UppercaseString string `validate:"uppercase"` StrPtrLt *string `validate:"lt=1"`
Datetime string `validate:"datetime=2006-01-02"` StrPtrLte *string `validate:"lte=1"`
PostCode string `validate:"postcode_iso3166_alpha2=SG"` StrPtrGt *string `validate:"gt=10"`
PostCodeCountry string StrPtrGte *string `validate:"gte=10"`
PostCodeByField string `validate:"postcode_iso3166_alpha2_field=PostCodeCountry"` OneOfString string `validate:"oneof=red green"`
BooleanString string `validate:"boolean"` OneOfInt int `validate:"oneof=5 63"`
UniqueSlice []string `validate:"unique"`
UniqueArray [3]string `validate:"unique"`
UniqueMap map[string]string `validate:"unique"`
JSONString string `validate:"json"`
JWTString string `validate:"jwt"`
LowercaseString string `validate:"lowercase"`
UppercaseString string `validate:"uppercase"`
Datetime string `validate:"datetime=2006-01-02"`
PostCode string `validate:"postcode_iso3166_alpha2=SG"`
PostCodeCountry string
PostCodeByField string `validate:"postcode_iso3166_alpha2_field=PostCodeCountry"`
BooleanString string `validate:"boolean"`
} }
var test Test var test Test
@ -159,6 +182,20 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234" test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234" test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "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.MaxString = "1234"
test.MaxNumber = 2000 test.MaxNumber = 2000
@ -610,6 +647,50 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple", ns: "Test.RequiredMultiple",
expected: "RequiredMultiple is a required field", 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", ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen must be at least 10 characters in length", expected: "StrPtrMinLen must be at least 10 characters in length",

Loading…
Cancel
Save