This library is used to translate Zod's default error messages.
yarn add zod-i18n-map i18next
This library depends on i18next
.
import i18next from 'i18next'
import { z } from 'zod'
import { zodI18nMap } from 'zod-i18n-map'
// Import your language translation files
import translation from 'zod-i18n-map/locales/ja/zod.json'
// lng and resources key depend on your locale.
i18next.init({
lng: 'ja',
resources: {
ja: { zod: translation },
},
interpolation: {
// https://www.i18next.com/translation-function/nesting#passing-nesting-to-interpolated
skipOnVariables: false
}
});
z.setErrorMap(zodI18nMap)
const schema = z.string().email()
schema.parse('foo') // メールアドレスの形式で入力してください。
zod-i18n-map
contains translation files for several locals. See here if your language is included.
It is also possible to create and edit translation files. You can use this English translation file as a basis for rewriting it in your language.
If you have created a translation file for a language not yet in the repository, please send us a pull request.
Many users will want to use it with next-i18next
(i.e. on Next.js). This example summarizes how to use with it.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the MIT License - see the LICENSE file for details