mirror of
https://github.com/Fishwaldo/validator.git
synced 2025-07-09 06:32:32 +00:00
enhancement: add zh translations for tag alphaunicode,alphanumunicode,containsrune,startswith,endswith (#799)
This commit is contained in:
parent
44c2696cbd
commit
61a982014e
2 changed files with 196 additions and 111 deletions
|
@ -1000,6 +1000,16 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
|
||||||
translation: "{0}只能包含字母和数字",
|
translation: "{0}只能包含字母和数字",
|
||||||
override: false,
|
override: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tag: "alphanumunicode",
|
||||||
|
translation: "{0}只能包含字母数字和Unicode字符",
|
||||||
|
override: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: "alphaunicode",
|
||||||
|
translation: "{0}只能包含字母和Unicode字符",
|
||||||
|
override: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
tag: "numeric",
|
tag: "numeric",
|
||||||
translation: "{0}必须是一个有效的数值",
|
translation: "{0}必须是一个有效的数值",
|
||||||
|
@ -1090,6 +1100,21 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
|
||||||
return t
|
return t
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tag: "containsrune",
|
||||||
|
translation: "{0}必须包含字符'{1}'",
|
||||||
|
override: false,
|
||||||
|
customTransFunc: func(ut ut.Translator, fe validator.FieldError) string {
|
||||||
|
|
||||||
|
t, err := ut.T(fe.Tag(), fe.Field(), fe.Param())
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("警告: 翻译字段错误: %#v", fe)
|
||||||
|
return fe.(error).Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
tag: "excludes",
|
tag: "excludes",
|
||||||
translation: "{0}不能包含文本'{1}'",
|
translation: "{0}不能包含文本'{1}'",
|
||||||
|
@ -1135,6 +1160,36 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
|
||||||
return t
|
return t
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tag: "endswith",
|
||||||
|
translation: "{0}必须以文本'{1}'结尾",
|
||||||
|
override: false,
|
||||||
|
customTransFunc: func(ut ut.Translator, fe validator.FieldError) string {
|
||||||
|
|
||||||
|
t, err := ut.T(fe.Tag(), fe.Field(), fe.Param())
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("警告: 翻译字段错误: %#v", fe)
|
||||||
|
return fe.(error).Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tag: "startswith",
|
||||||
|
translation: "{0}必须以文本'{1}'开头",
|
||||||
|
override: false,
|
||||||
|
customTransFunc: func(ut ut.Translator, fe validator.FieldError) string {
|
||||||
|
|
||||||
|
t, err := ut.T(fe.Tag(), fe.Field(), fe.Param())
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("警告: 翻译字段错误: %#v", fe)
|
||||||
|
return fe.(error).Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
return t
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
tag: "isbn",
|
tag: "isbn",
|
||||||
translation: "{0}必须是一个有效的ISBN编号",
|
translation: "{0}必须是一个有效的ISBN编号",
|
||||||
|
|
|
@ -80,6 +80,8 @@ func TestTranslations(t *testing.T) {
|
||||||
LteFieldString string `validate:"ltefield=MaxString"`
|
LteFieldString string `validate:"ltefield=MaxString"`
|
||||||
AlphaString string `validate:"alpha"`
|
AlphaString string `validate:"alpha"`
|
||||||
AlphanumString string `validate:"alphanum"`
|
AlphanumString string `validate:"alphanum"`
|
||||||
|
AlphanumUnicodeString string `validate:"alphanumunicode"`
|
||||||
|
AlphaUnicodeString string `validate:"alphaunicode"`
|
||||||
NumericString string `validate:"numeric"`
|
NumericString string `validate:"numeric"`
|
||||||
NumberString string `validate:"number"`
|
NumberString string `validate:"number"`
|
||||||
HexadecimalString string `validate:"hexadecimal"`
|
HexadecimalString string `validate:"hexadecimal"`
|
||||||
|
@ -94,9 +96,12 @@ func TestTranslations(t *testing.T) {
|
||||||
Base64 string `validate:"base64"`
|
Base64 string `validate:"base64"`
|
||||||
Contains string `validate:"contains=purpose"`
|
Contains string `validate:"contains=purpose"`
|
||||||
ContainsAny string `validate:"containsany=!@#$"`
|
ContainsAny string `validate:"containsany=!@#$"`
|
||||||
|
ContainsRune string `validate:"containsrune=☻"`
|
||||||
Excludes string `validate:"excludes=text"`
|
Excludes string `validate:"excludes=text"`
|
||||||
ExcludesAll string `validate:"excludesall=!@#$"`
|
ExcludesAll string `validate:"excludesall=!@#$"`
|
||||||
ExcludesRune string `validate:"excludesrune=☻"`
|
ExcludesRune string `validate:"excludesrune=☻"`
|
||||||
|
EndsWith string `validate:"endswith=end"`
|
||||||
|
StartsWith string `validate:"startswith=start"`
|
||||||
ISBN string `validate:"isbn"`
|
ISBN string `validate:"isbn"`
|
||||||
ISBN10 string `validate:"isbn10"`
|
ISBN10 string `validate:"isbn10"`
|
||||||
ISBN13 string `validate:"isbn13"`
|
ISBN13 string `validate:"isbn13"`
|
||||||
|
@ -172,6 +177,8 @@ func TestTranslations(t *testing.T) {
|
||||||
|
|
||||||
test.AlphaString = "abc3"
|
test.AlphaString = "abc3"
|
||||||
test.AlphanumString = "abc3!"
|
test.AlphanumString = "abc3!"
|
||||||
|
test.AlphanumUnicodeString = "abc3啊!"
|
||||||
|
test.AlphaUnicodeString = "abc3啊"
|
||||||
test.NumericString = "12E.00"
|
test.NumericString = "12E.00"
|
||||||
test.NumberString = "12E"
|
test.NumberString = "12E"
|
||||||
|
|
||||||
|
@ -179,6 +186,9 @@ func TestTranslations(t *testing.T) {
|
||||||
test.ExcludesAll = "This is Great!"
|
test.ExcludesAll = "This is Great!"
|
||||||
test.ExcludesRune = "Love it ☻"
|
test.ExcludesRune = "Love it ☻"
|
||||||
|
|
||||||
|
test.EndsWith = "this is some test text"
|
||||||
|
test.StartsWith = "this is some test text"
|
||||||
|
|
||||||
test.ASCII = "カタカナ"
|
test.ASCII = "カタカナ"
|
||||||
test.PrintableASCII = "カタカナ"
|
test.PrintableASCII = "カタカナ"
|
||||||
|
|
||||||
|
@ -329,6 +339,14 @@ func TestTranslations(t *testing.T) {
|
||||||
ns: "Test.ISBN13",
|
ns: "Test.ISBN13",
|
||||||
expected: "ISBN13必须是一个有效的ISBN-13编号",
|
expected: "ISBN13必须是一个有效的ISBN-13编号",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ns: "Test.EndsWith",
|
||||||
|
expected: "EndsWith必须以文本'end'结尾",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ns: "Test.StartsWith",
|
||||||
|
expected: "StartsWith必须以文本'start'开头",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ns: "Test.Excludes",
|
ns: "Test.Excludes",
|
||||||
expected: "Excludes不能包含文本'text'",
|
expected: "Excludes不能包含文本'text'",
|
||||||
|
@ -341,6 +359,10 @@ func TestTranslations(t *testing.T) {
|
||||||
ns: "Test.ExcludesRune",
|
ns: "Test.ExcludesRune",
|
||||||
expected: "ExcludesRune不能包含'☻'",
|
expected: "ExcludesRune不能包含'☻'",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ns: "Test.ContainsRune",
|
||||||
|
expected: "ContainsRune必须包含字符'☻'",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ns: "Test.ContainsAny",
|
ns: "Test.ContainsAny",
|
||||||
expected: "ContainsAny必须包含至少一个以下字符'!@#$'",
|
expected: "ContainsAny必须包含至少一个以下字符'!@#$'",
|
||||||
|
@ -397,6 +419,14 @@ func TestTranslations(t *testing.T) {
|
||||||
ns: "Test.NumericString",
|
ns: "Test.NumericString",
|
||||||
expected: "NumericString必须是一个有效的数值",
|
expected: "NumericString必须是一个有效的数值",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
ns: "Test.AlphaUnicodeString",
|
||||||
|
expected: "AlphaUnicodeString只能包含字母和Unicode字符",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ns: "Test.AlphanumUnicodeString",
|
||||||
|
expected: "AlphanumUnicodeString只能包含字母数字和Unicode字符",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
ns: "Test.AlphanumString",
|
ns: "Test.AlphanumString",
|
||||||
expected: "AlphanumString只能包含字母和数字",
|
expected: "AlphanumString只能包含字母和数字",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue