Skip to content

Integration with zod-i18n? #132

Closed Answered by DHFW
DHFW asked this question in Q&A
Apr 21, 2023 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I think I made the solution myself :)

In my i18n.ts configuration file I changed the defaultNS to an array like so:

  defaultNS: ['common', 'zod'],

In my root.tsx:

// in imports: 
import { makeZodI18nMap } from 'zod-i18n-map';

// In the app/ main component:
export default function App() {
  const { t, i18n } = useTranslation();
  z.setErrorMap(makeZodI18nMap({ t, handlePath: { ns: ['zod'] } }));

And then the messages are translated to the file in my public folder where the common.json is also placed.
The content of the zod.json is copied from the zod-i18n locales/de/zod.json file

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lgastler
Comment options

Answer selected by DHFW
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants