@ -16,7 +16,6 @@ import (
// RegisterDefaultTranslations registers a set of default translations
// RegisterDefaultTranslations registers a set of default translations
// for all built in tag's in validator; you may add your own as desired.
// for all built in tag's in validator; you may add your own as desired.
func RegisterDefaultTranslations ( v * validator . Validate , trans ut . Translator ) ( err error ) {
func RegisterDefaultTranslations ( v * validator . Validate , trans ut . Translator ) ( err error ) {
translations := [ ] struct {
translations := [ ] struct {
tag string
tag string
translation string
translation string
@ -32,7 +31,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "len" ,
tag : "len" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "len-string" , "{0} must be {1} in length" , false ) ; err != nil {
if err = ut . Add ( "len-string" , "{0} must be {1} in length" , false ) ; err != nil {
return
return
}
}
@ -61,10 +59,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
}
}
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
@ -123,7 +119,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "min" ,
tag : "min" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "min-string" , "{0} must be at least {1} in length" , false ) ; err != nil {
if err = ut . Add ( "min-string" , "{0} must be at least {1} in length" , false ) ; err != nil {
return
return
}
}
@ -152,10 +147,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
}
}
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
@ -214,7 +207,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "max" ,
tag : "max" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "max-string" , "{0} must be a maximum of {1} in length" , false ) ; err != nil {
if err = ut . Add ( "max-string" , "{0} must be a maximum of {1} in length" , false ) ; err != nil {
return
return
}
}
@ -243,10 +235,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
}
}
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
@ -307,7 +297,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} is not equal to {1}" ,
translation : "{0} is not equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
fmt . Printf ( "warning: error translating FieldError: %#v" , fe )
fmt . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -322,7 +311,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} should not be equal to {1}" ,
translation : "{0} should not be equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
fmt . Printf ( "warning: error translating FieldError: %#v" , fe )
fmt . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -335,7 +323,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "lt" ,
tag : "lt" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "lt-string" , "{0} must be less than {1} in length" , false ) ; err != nil {
if err = ut . Add ( "lt-string" , "{0} must be less than {1} in length" , false ) ; err != nil {
return
return
}
}
@ -369,10 +356,8 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
}
}
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
var f64 float64
var f64 float64
@ -380,7 +365,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
var kind reflect . Kind
var kind reflect . Kind
fn := func ( ) ( err error ) {
fn := func ( ) ( err error ) {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
}
}
@ -456,7 +440,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "lte" ,
tag : "lte" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "lte-string" , "{0} must be at maximum {1} in length" , false ) ; err != nil {
if err = ut . Add ( "lte-string" , "{0} must be at maximum {1} in length" , false ) ; err != nil {
return
return
}
}
@ -492,7 +475,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
var f64 float64
var f64 float64
@ -500,7 +482,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
var kind reflect . Kind
var kind reflect . Kind
fn := func ( ) ( err error ) {
fn := func ( ) ( err error ) {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
}
}
@ -576,7 +557,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "gt" ,
tag : "gt" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "gt-string" , "{0} must be greater than {1} in length" , false ) ; err != nil {
if err = ut . Add ( "gt-string" , "{0} must be greater than {1} in length" , false ) ; err != nil {
return
return
}
}
@ -612,7 +592,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
var f64 float64
var f64 float64
@ -620,7 +599,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
var kind reflect . Kind
var kind reflect . Kind
fn := func ( ) ( err error ) {
fn := func ( ) ( err error ) {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
}
}
@ -696,7 +674,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
{
{
tag : "gte" ,
tag : "gte" ,
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
customRegisFunc : func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( "gte-string" , "{0} must be at least {1} in length" , false ) ; err != nil {
if err = ut . Add ( "gte-string" , "{0} must be at least {1} in length" , false ) ; err != nil {
return
return
}
}
@ -732,7 +709,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
return
return
} ,
} ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
var err error
var err error
var t string
var t string
var f64 float64
var f64 float64
@ -740,7 +716,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
var kind reflect . Kind
var kind reflect . Kind
fn := func ( ) ( err error ) {
fn := func ( ) ( err error ) {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
if idx := strings . Index ( fe . Param ( ) , "." ) ; idx != - 1 {
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
digits = uint64 ( len ( fe . Param ( ) [ idx + 1 : ] ) )
}
}
@ -818,7 +793,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be equal to {1}" ,
translation : "{0} must be equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -833,7 +807,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be equal to {1}" ,
translation : "{0} must be equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -848,7 +821,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} cannot be equal to {1}" ,
translation : "{0} cannot be equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -863,7 +835,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be greater than {1}" ,
translation : "{0} must be greater than {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -878,7 +849,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be greater than or equal to {1}" ,
translation : "{0} must be greater than or equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -893,7 +863,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be less than {1}" ,
translation : "{0} must be less than {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -908,7 +877,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be less than or equal to {1}" ,
translation : "{0} must be less than or equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -923,7 +891,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} cannot be equal to {1}" ,
translation : "{0} cannot be equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -938,7 +905,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be greater than {1}" ,
translation : "{0} must be greater than {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -953,7 +919,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be greater than or equal to {1}" ,
translation : "{0} must be greater than or equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -968,7 +933,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be less than {1}" ,
translation : "{0} must be less than {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -983,7 +947,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must be less than or equal to {1}" ,
translation : "{0} must be less than or equal to {1}" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1073,7 +1036,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must contain the text '{1}'" ,
translation : "{0} must contain the text '{1}'" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1088,7 +1050,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} must contain at least one of the following characters '{1}'" ,
translation : "{0} must contain at least one of the following characters '{1}'" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1103,7 +1064,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} cannot contain the text '{1}'" ,
translation : "{0} cannot contain the text '{1}'" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1118,7 +1078,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} cannot contain any of the following characters '{1}'" ,
translation : "{0} cannot contain any of the following characters '{1}'" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1133,7 +1092,6 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} cannot contain the following '{1}'" ,
translation : "{0} cannot contain the following '{1}'" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1341,7 +1299,34 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
translation : "{0} does not match the {1} format" ,
translation : "{0} does not match the {1} format" ,
override : false ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
return fe . ( error ) . Error ( )
}
return t
} ,
} ,
{
tag : "postcode_iso3166_alpha2" ,
translation : "{0} does not match postcode format of {1} country" ,
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 ( "warning: error translating FieldError: %#v" , fe )
return fe . ( error ) . Error ( )
}
return t
} ,
} ,
{
tag : "postcode_iso3166_alpha2_field" ,
translation : "{0} does not match postcode format of country in {1} field" ,
override : false ,
customTransFunc : func ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) , fe . Param ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )
@ -1356,17 +1341,11 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
for _ , t := range translations {
for _ , t := range translations {
if t . customTransFunc != nil && t . customRegisFunc != nil {
if t . customTransFunc != nil && t . customRegisFunc != nil {
err = v . RegisterTranslation ( t . tag , trans , t . customRegisFunc , t . customTransFunc )
err = v . RegisterTranslation ( t . tag , trans , t . customRegisFunc , t . customTransFunc )
} else if t . customTransFunc != nil && t . customRegisFunc == nil {
} else if t . customTransFunc != nil && t . customRegisFunc == nil {
err = v . RegisterTranslation ( t . tag , trans , registrationFunc ( t . tag , t . translation , t . override ) , t . customTransFunc )
err = v . RegisterTranslation ( t . tag , trans , registrationFunc ( t . tag , t . translation , t . override ) , t . customTransFunc )
} else if t . customTransFunc == nil && t . customRegisFunc != nil {
} else if t . customTransFunc == nil && t . customRegisFunc != nil {
err = v . RegisterTranslation ( t . tag , trans , t . customRegisFunc , translateFunc )
err = v . RegisterTranslation ( t . tag , trans , t . customRegisFunc , translateFunc )
} else {
} else {
err = v . RegisterTranslation ( t . tag , trans , registrationFunc ( t . tag , t . translation , t . override ) , translateFunc )
err = v . RegisterTranslation ( t . tag , trans , registrationFunc ( t . tag , t . translation , t . override ) , translateFunc )
}
}
@ -1380,21 +1359,16 @@ func RegisterDefaultTranslations(v *validator.Validate, trans ut.Translator) (er
}
}
func registrationFunc ( tag string , translation string , override bool ) validator . RegisterTranslationsFunc {
func registrationFunc ( tag string , translation string , override bool ) validator . RegisterTranslationsFunc {
return func ( ut ut . Translator ) ( err error ) {
return func ( ut ut . Translator ) ( err error ) {
if err = ut . Add ( tag , translation , override ) ; err != nil {
if err = ut . Add ( tag , translation , override ) ; err != nil {
return
return
}
}
return
return
}
}
}
}
func translateFunc ( ut ut . Translator , fe validator . FieldError ) string {
func translateFunc ( ut ut . Translator , fe validator . FieldError ) string {
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) )
t , err := ut . T ( fe . Tag ( ) , fe . Field ( ) )
if err != nil {
if err != nil {
log . Printf ( "warning: error translating FieldError: %#v" , fe )
log . Printf ( "warning: error translating FieldError: %#v" , fe )