feat(translations/zh): add Chinese translations for requiredXXX tags

Add Chinese translations and tests for these tags:
     excluded_if
     excluded_unless
     excluded_with
     excluded_with_all
     excluded_without
     excluded_without_all

Add Chinese translations tests for these tags:
     required_if
     required_unless
     required_with
     required_with_all
     required_without
     required_without_all
pull/987/head
violin0622 2 years ago
parent 2d336e25a6
commit dc1e874cc4
  1. 35
      translations/zh/zh.go
  2. 96
      translations/zh/zh_test.go

@ -59,6 +59,41 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation: "{0}为必填字段",
override: false,
},
{
tag: "excluded_if",
translation: "{0}为排除字段",
override: false,
},
{
tag: "excluded_unless",
translation: "{0}为排除字段",
override: false,
},
{
tag: "excluded_with",
translation: "{0}为排除字段",
override: false,
},
{
tag: "excluded_with_all",
translation: "{0}为排除字段",
override: false,
},
{
tag: "excluded_without",
translation: "{0}为排除字段",
override: false,
},
{
tag: "excluded_without_all",
translation: "{0}为排除字段",
override: false,
},
{
tag: "isdefault",
translation: "{0}为排除字段",
override: false,
},
{
tag: "len",
customRegisFunc: func(ut ut.Translator) (err error) {

@ -22,12 +22,24 @@ func TestTranslations(t *testing.T) {
Equal(t, err, nil)
type Inner struct {
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
LtCSFieldString string
LteCSFieldString string
EqCSFieldString string
NeCSFieldString string
GtCSFieldString string
GteCSFieldString string
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 {
@ -35,6 +47,19 @@ func TestTranslations(t *testing.T) {
RequiredString string `validate:"required"`
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"`
@ -155,6 +180,21 @@ func TestTranslations(t *testing.T) {
test.Inner.EqCSFieldString = "1234"
test.Inner.GtCSFieldString = "1234"
test.Inner.GteCSFieldString = "1234"
test.Inner.RequiredIf = "abcd"
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
@ -624,6 +664,50 @@ func TestTranslations(t *testing.T) {
ns: "Test.RequiredMultiple",
expected: "RequiredMultiple为必填字段",
},
{
ns: "Test.RequiredUnless",
expected: "RequiredUnless为必填字段",
},
{
ns: "Test.RequiredWith",
expected: "RequiredWith为必填字段",
},
{
ns: "Test.RequiredWithAll",
expected: "RequiredWithAll为必填字段",
},
{
ns: "Test.RequiredWithout",
expected: "RequiredWithout为必填字段",
},
{
ns: "Test.RequiredWithoutAll",
expected: "RequiredWithoutAll为必填字段",
},
{
ns: "Test.ExcludedIf",
expected: "ExcludedIf为排除字段",
},
{
ns: "Test.ExcludedUnless",
expected: "ExcludedUnless为排除字段",
},
{
ns: "Test.ExcludedWith",
expected: "ExcludedWith为排除字段",
},
{
ns: "Test.ExcludedWithAll",
expected: "ExcludedWithAll为排除字段",
},
{
ns: "Test.ExcludedWithout",
expected: "ExcludedWithout为排除字段",
},
{
ns: "Test.ExcludedWithoutAll",
expected: "ExcludedWithoutAll为排除字段",
},
{
ns: "Test.StrPtrMinLen",
expected: "StrPtrMinLen长度必须至少为10个字符",

Loading…
Cancel
Save