jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
34.02k stars 2.79k forks source link

How to handle i18n/localization? #158

Closed michalkvasnicak closed 7 years ago

michalkvasnicak commented 7 years ago

For example, if we are using yup schema for validation in formik, it is easy to translate messages, but problem occurs when we are using string().min() and the error message should be correct for a given number in min() validator.

Currently formik is adding error messages as a string, so it basically strips params from yup.ValidationError. In order to handle this, we have to somehow wrap all validators in yup to custom validators, just to translate messages correctly.

Is there a way how to handle this in formik?

jaredpalmer commented 7 years ago

AFAIK Yup doesn't have a way of dealing with i18n. Thus, i would pick another validation library instead and pass its output to validate.

jaredpalmer commented 7 years ago

@michalkvasnicak If you settle on a validation lib you like that supports i18n, would you mind leaving a comment here so I can make an example for the Formik documentation?

guilhermedecampo commented 7 years ago

hey guys yup has support for i18n! https://github.com/jquense/yup#using-a-custom-locale-dictionary

jaredpalmer commented 7 years ago

I stand corrected ^^

michalkvasnicak commented 7 years ago

Yes it has, but I didn't know that it supports functions in locale until yesterday's evening, so now this issue can be closed :)