Skip to content

How to use my translations in validation messages using zod in sveltekit #3036

Discussion options

You must be logged in to vote

Although this does work, it is not the right solution for me. Zod is expecting a string when defining messages directly inside the schema. As well as my error component which is based on the FormErrors component from formsnap.

I looked into something different, Zod offers a setErrorMap function. I was inspired by an existing solution to translate zod messages for i18next zod-i18n.

I now create and set the global errorMap once in my layout's onMount function. Although not ideal, it works. Do you, from your experience, see any concerns doing it in this way?

I was rather hoping to set it in a earlier stage, like the hooks.server.ts file for instance, that didn't work, messages turned undefin…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@peterknijff
Comment options

@samuelstroschein
Comment options

@peterknijff
Comment options

Answer selected by peterknijff
@samuelstroschein
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants