-
Notifications
You must be signed in to change notification settings - Fork 20
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
Ability to translate error messages #18
Comments
+1 |
Hi, @texodont! Currently, there isn't a way to change the default message, but it should be trivial to update Basically, changing export default function createValidator(curriedDefinition, defaultMessageCreator) {
// ...
function validator(config, value, allValues) {
// ...
}
function clone(newDefaultMessageCreator) {
return createValidator(curriedDefinition, newDefaultMessageCreator);
}
validator.clone = clone;
return validator;
}
// Later on
const esNecesario = isRequired.clone(field => `${field} es necesario`);
isRequired('Foo')(); // Foo is required
esNecesario('Foo')(); // Foo es necesario Would you find something like that to be useful? Thanks for the idea! |
@jfairbank I like the simplicity of your solution above, but it has the downside of needing to pre-define the language-translated-validators and know which one to reference in code. In my experience that's not how i18n typically works - at least not on my projects. I'm trying to figure out a way to swap in a library like
I'm having trouble thinking about how to tie these together. It's easy enough to set up a validator to use a message object, but I can't figure out where/how I'd pass in the formatMessage function:
Any ideas or thoughts? Am I missing part of the API that would make this easier? |
Definitely needed, english-only messages are not good. :/ One simple approach could be to overrides the default messages when calling
This is assuming there is only one error message per validator. If that's not the case (several possible errors) it would be a bit harder but still doable. |
@Vadorequest |
Hi! Thanks for this great library, validation becomes really enjoyable.
Is it possible to change default error messages (to support different languages for example) without copy-paste all validator or passing custom message on every use?
The text was updated successfully, but these errors were encountered: