ajv-i18n repository (opens new window)

# ajv-i18n

Internationalised error messages for Ajv (opens new window) - superfast JSON validator for JSON Schema and JSON Type Definition.

Build Status (opens new window) npm (opens new window) Coverage Status (opens new window) Gitter (opens new window)

# Supported locales

locale language contributor draft-04 draft-061 draft-072 draft
2019-093
/2020-124
JTD5
๐Ÿ‡ฌ๐Ÿ‡ง en English โœ“ โœ“ โœ“ โœ“ โœ“
AR ar Arabic Mahmoud-Mardeni (opens new window) โœ“ โœ“ โœ“ - -
CA ca Catalan alexandreec (opens new window) โœ“ โœ“ โœ“ - *
๐Ÿ‡จ๐Ÿ‡ฟ cs Czech kiskovacs (opens new window)
NAM0007 (opens new window)
โœ“
โœ“

โœ“
- *
๐Ÿ‡ฉ๐Ÿ‡ช de German jmtoball (opens new window)
gflohr (opens new window)
โœ“
โœ“

โœ“
โœ“
โœ“
๐Ÿ‡ช๐Ÿ‡ธ es Spanish jpablom (opens new window) โœ“ โœ“ โœ“ - *
๐Ÿ‡ซ๐Ÿ‡ท fr French monlouisj (opens new window)
Telokis (opens new window)
โœ“
โœ“

โœ“
- *
๐Ÿ‡ญ๐Ÿ‡บ hu Hungarian szilveszter9 (opens new window) โœ“ - - - *
๐Ÿ‡ฎ๐Ÿ‡ฉ id Indonesian ekoeryanto (opens new window) โœ“ โœ“ โœ“ - *
๐Ÿ‡ฎ๐Ÿ‡น it Italian jasoniangreen (opens new window)
lucacorti (opens new window)
โœ“

โœ“

โœ“

โœ“

โœ“
๐Ÿ‡ฏ๐Ÿ‡ต ja Japanese gilgongo (opens new window) โœ“ - - - *
๐Ÿ‡ฐ๐Ÿ‡ท ko Korean MinByeongDon (opens new window) โœ“ โœ“ โœ“ - *
๐Ÿ‡ณ๐Ÿ‡ด nb Norwegian bokmรฅl mtramm (opens new window) โœ“ โœ“ - - *
๐Ÿ‡ณ๐Ÿ‡ฑ nl Dutch pimlie (opens new window)
niekvb (opens new window)
โœ“ โœ“ โœ“
โœ“

โœ“
๐Ÿ‡ต๐Ÿ‡ฑ pl Polish danielzurawski (opens new window) โœ“ - - - *
๐Ÿ‡ง๐Ÿ‡ท pt-BR Portuguรชs - Brasil marcosrava (opens new window)
ggondim (opens new window)
โœ“ โœ“ โœ“
โœ“

โœ“
๐Ÿ‡ท๐Ÿ‡บ ru Russian โœ“ โœ“ โœ“ โœ“ โœ“
๐Ÿ‡ธ๐Ÿ‡ฐ sk Slovak kiskovacs (opens new window) โœ“ โœ“ - - *
๐Ÿ‡ธ๐Ÿ‡ช sv Swedish limmen (opens new window) โœ“ โœ“ - - *
๐Ÿ‡น๐Ÿ‡ญ th Thai encX (opens new window) โœ“ โœ“ โœ“ โœ“ โœ“
๐Ÿ‡จ๐Ÿ‡ณ zh Chinese jinzhubaofu (opens new window)
leuction (opens new window)
โœ“

โœ“

โœ“

โœ“

โœ“
๐Ÿ‡น๐Ÿ‡ผ zh-TW Chinese - Taiwan minipai (opens new window) โœ“ โœ“ โœ“ โœ“ โœ“

1 added boolean schema, keywords const, contains, propertyNames

2 added keywords if/then/else

3 added messages for keywords unevaluatedProperties, unevaluatedItems, dependentRequired

4 keyword items messages

5 JSON Type Definition

* discriminator form messages are not translated

Please contribute locales that you need to use if they are missing or incomplete.

# Install

Using npm:

npm install ajv-i18n

# Usage

In node:

const Ajv = require("ajv") // version >= 8.0.0
const localize = require("ajv-i18n")
// or for JSON Type Definition
// const localize = require("ajv-i18n/localize/jtd")

const ajv = Ajv({allErrors: true, messages: false})
const validate = ajv.compile(schema)
const valid = validate(data)

if (!valid) {
  // ru for Russian
  localize.ru(validate.errors)
  // string with all errors and data paths
  console.log(ajv.errorsText(validate.errors, {separator: '\n'}))
}

To require only necessary locales (e.g., with browserify):

const localize_ru = require('ajv-i18n/localize/ru')
// or for JSON Type Definition
// const localize_ru = require('ajv-i18n/localize/ru/jtd')

or

const localize = {
  en: require('ajv-i18n/localize/en'),
  ru: require('ajv-i18n/localize/ru'),
}

See Ajv docs (opens new window) for more information.

# Tests

npm install
git submodule update --init
npm test

# Contributing

Functions that localize error messages are generated using doT template localize.jst (opens new window), JSON Schema messages (opens new window) and JSON Type Definition messages (opens new window). Templates are pre-compiled, so doT is not a run-time dependency.

npm run build - compiles functions to localize (opens new window) folder.

# Contributors of locales

danielzurawski (opens new window) szilveszter9 (opens new window) jmtoball (opens new window) gilgongo (opens new window) jasoniangreen (opens new window) jpablom (opens new window) limmen (opens new window) jinzhubaofu (opens new window) kiskovacs (opens new window) mahmoud-mardeni (opens new window) monlouisj (opens new window) marcosrava (opens new window) mtramm (opens new window) Mahmoud-Mardeni (opens new window) leuction (opens new window) lucacorti (opens new window) minipai (opens new window) encX (opens new window) pimlie (opens new window) MinByeongDon (opens new window) gflohr (opens new window) ekoeryanto (opens new window) Telokis (opens new window) alexandreec (opens new window) ggondim (opens new window) niekvb (opens new window) NAM0007 (opens new window)

# Enterprise support

ajv-i18n package is a part of Tidelift enterprise subscription (opens new window) - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.

# Security contact

To report a security vulnerability, please use the Tidelift security contact (opens new window). Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.

# License

MIT (opens new window)