jquense / yup

Dead simple Object schema validation
MIT License
22.95k stars 935 forks source link

Yup setLocale() requiring yup.LocaleObject type #2063

Closed calicoder77 closed 1 year ago

calicoder77 commented 1 year ago

Good day,

I have the following code and was wondering how I can transform a string value like en into a yup.LocaleObject type so I can insert it into a setLocale() call? Appreciate any tips and help, thanks

import * as yup from 'yup'

yup.setLocale() <---- I have a string method returning `en` but this parameter needs to be a custom type of yup.LocaleObject
jquense commented 1 year ago

I'm not sure I understand the question, the method accepts an object of messages not a string

calicoder77 commented 1 year ago

I'm not sure I understand the question, the method accepts an object of messages not a string

Good afternoon @jquense, I have multiple language codes (en, fr, sp, it, etc...) and I see that the Yup setLocale() method requires a LocaleObject parameter passed to it. I'm just wondering how to convert that language code string to a LocaleObject so I can feed it to setLocale()? Is there a method in the Yup package that does that for example as I took a look at the docs and don't see it mentioned.

jquense commented 1 year ago

Ah no we don't include other translations besides English, you need to provide the translated strings or whatever. There is a simple example of how you might want to do that in the docs https://github.com/jquense/yup#localization-and-i18n but it's up to you