Using wuchale with Zod error messages #253
-
|
I have a function that returns error messages. Wuchale picks it up and I can translate it, but when running dev or building for production I get an error at the site (Zod schema) where I call the Is it possible to use Wuchale translations with Zod error messages? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
Hi @brandonpittman, I am not sure if I understand how you were using the As for the locale setup, the key is when the strings are normally accessed. If they are top level variables for example, they are accessed right after the module is parsed before wuchale can have a chance to swap them. Even if they are inside functions, if the function is called from a top level declaration, it has the same effect. So the function should be called inside a request (backend) or when rendering (frontend). Of course this doesn't apply to the Svelte adapter because even top level values can be reactive there so they can be swapped. |
Beta Was this translation helpful? Give feedback.
Turns out I was on the right track.
Declaring the Zod error message with something like
z.string({error: () => get_error('error')})works. I just missed a file that used theget_errorfunction. Once I converted the other file's usage to the function version, everything worked fine.