-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nil pointer while translating min/gt in ru_RU locale #593
Comments
Face the same problem. Also when use FR locale, it translate to russian.
Output: |
Thanks for reporting, will try to take a look this week, first time of heard of this issue. |
Thank you! |
same situation with ru locale |
@deankarn |
Hi, I've tried to check the issue but could not replicate. Tested it with The output of
Check code below. main_test.go: package main
import (
"log"
"testing"
"github.com/go-playground/locales"
"github.com/go-playground/locales/en_GB"
"github.com/go-playground/locales/fr_FR"
"github.com/go-playground/locales/pt_PT"
"github.com/go-playground/locales/ru_RU"
ut "github.com/go-playground/universal-translator"
"github.com/go-playground/validator/v10"
"github.com/go-playground/validator/v10/translations/en"
"github.com/go-playground/validator/v10/translations/fr"
"github.com/go-playground/validator/v10/translations/pt"
"github.com/go-playground/validator/v10/translations/ru"
)
type S struct {
Field string `validate:"gt=2"`
}
func Test593(t *testing.T) {
testCases := []struct {
Locale locales.Translator
RT func(v *validator.Validate, trans ut.Translator) (err error)
}{
{
Locale: pt_PT.New(),
RT: pt.RegisterDefaultTranslations,
},
{
Locale: en_GB.New(),
RT: en.RegisterDefaultTranslations,
},
{
Locale: ru_RU.New(),
RT: ru.RegisterDefaultTranslations,
},
{
Locale: fr_FR.New(),
RT: fr.RegisterDefaultTranslations,
},
}
for _, tc := range testCases {
locale := tc.Locale
uni := ut.New(locale, locale)
trans, _ := uni.GetTranslator(locale.Locale())
validate := validator.New()
_ = tc.RT(validate, trans)
a := &S{
Field: "a",
}
err := validate.Struct(a)
if err != nil {
for _, e := range err.(validator.ValidationErrors) {
log.Println(e.Translate(trans))
}
}
}
} go.mod: module validator593
go 1.17
require (
github.com/go-playground/locales v0.14.0
github.com/go-playground/universal-translator v0.18.0
github.com/go-playground/validator/v10 v10.10.0
)
require (
github.com/leodido/go-urn v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
golang.org/x/text v0.3.7 // indirect
) |
This was fixed in #814 |
Package version eg. v8, v9:
github.com/go-playground/validator/v10 v10.2.0
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
Issue, Question or Enhancement:
Trying to add validation with plurals in errors in ru_RU locale. Got nil pointer panic. What am I doing wrong?
Code sample, to showcase or reproduce:
This code leads to panic:
Panic:
The same code in en_GB locale works fine:
Result:
The text was updated successfully, but these errors were encountered: