Skip to content

Arturo-Lopez/zod-i18n

 
 

Repository files navigation

npm version codecov CI

hero

Zod Internationalization

This library is used to translate Zod's default error messages.

Installation

yarn add zod-i18n-map i18next

This library depends on i18next.

How to Use

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') // メールアドレスの形式で入力してください。

Translation Files

zod-i18n-map contains translation files for several locales. 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.

Use with next-i18next

Many users will want to use it with next-i18next (i.e. on Next.js). This example summarizes how to use with it.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

License

This project is licensed under the MIT License - see the LICENSE file for details

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):

Aiji Uejima
Aiji Uejima

💻 🌍 ⚠️ 🤔
Ismail Ajizou
Ismail Ajizou

🌍 ⚠️
Mohammed Maher
Mohammed Maher

🌍 ⚠️
Luiz Oliveira Montedonio
Luiz Oliveira Montedonio

🌍 ⚠️
Izayoi Hibiki
Izayoi Hibiki

🌍 ⚠️
Hrafnkell Baldursson
Hrafnkell Baldursson

🌍 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!

About

Useful for translating zod error messages.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.6%
  • Shell 0.4%