trans.go 559 B

123456789101112131415161718192021
  1. package helpers
  2. import (
  3. "github.com/go-playground/locales/ru"
  4. "github.com/go-playground/universal-translator"
  5. "github.com/go-playground/validator/v10"
  6. ruTranslations "github.com/go-playground/validator/v10/translations/ru"
  7. )
  8. func GetDefaultTranslator(v *validator.Validate) (ut.Translator, error) {
  9. var err error
  10. localeRu := ru.New()
  11. uniTrans := ut.New(localeRu, localeRu)
  12. trans, _ := uniTrans.GetTranslator(localeRu.Locale())
  13. if err = ruTranslations.RegisterDefaultTranslations(v, trans); err != nil {
  14. return nil, err
  15. }
  16. return trans, nil
  17. }