Replies: 4 comments 3 replies
-
Instead of using plain message error on zod validation rule, you can use a translation key then just create an Error component that get the key and put it into translate function. For example:
|
Beta Was this translation helpful? Give feedback.
-
Any progress? |
Beta Was this translation helpful? Give feedback.
-
need translated error messages for zod |
Beta Was this translation helpful? Give feedback.
-
If anyone stumbled upon this thread, this may be useful to you: https://github.com/orgs/react-hook-form/discussions/9452 (looks like possible solution is to pass t function to resolver function) ie: |
Beta Was this translation helpful? Give feedback.
-
Hi there,
I'm trying to create a form handling layer in our app and have come across an issue which I could not find the solution for:
I want to be able to display translated error messages. All the examples that I saw up until now suggest that the formatted message for the end user, should come from the schema itself.
The common example that I have come across is something like the following:
In my case, I have to do something like this:
This has 2 big disadvantages: The schema cannot be reused outside of react, and the type cannot be auto-inferred and used in another module.
The ideal solution would be to get more information from FieldError in react-hook-form,
Right now, for this error I would get something like the following:
This is the data that zod provides:
Had I received the complete information from
zod
, I could've translated the message properly. Which is impossible with the information fromFieldError
.Any recommendations? Am I doing something wrong?
Beta Was this translation helpful? Give feedback.
All reactions