GithubHelp home page GithubHelp logo

zod-i18n's Introduction

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 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.

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

zod-i18n's People

Contributors

aiji42 avatar maherapp avatar ismailajizou avatar montedonioluiz avatar izayoi-hibiki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.