๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’
Socket
DemoInstallSign in
Socket

ajv-i18n

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ajv-i18n

Internationalised error messages for Ajv JSON validator

4.2.0
latest
Source
npm
Version published
Weekly downloads
140K
-17.1%
Maintainers
1
Weekly downloads
ย 
Created

What is ajv-i18n?

The ajv-i18n package provides internationalization (i18n) support for the Ajv JSON schema validator. It allows you to generate error messages in different languages, making it easier to localize your applications.

What are ajv-i18n's main functionalities?

Localizing error messages

This feature allows you to localize error messages generated by Ajv. In this example, the error messages are localized to Chinese using the `localize.zh` function.

const Ajv = require('ajv');
const localize = require('ajv-i18n');

const ajv = new Ajv();
const schema = { type: 'object', properties: { foo: { type: 'string' } }, required: ['foo'], additionalProperties: false };
const validate = ajv.compile(schema);
const data = { bar: 2 };

const valid = validate(data);
if (!valid) {
  localize.zh(validate.errors); // Localize errors to Chinese
  console.log(validate.errors);
}

Supporting multiple languages

This feature demonstrates the ability to support multiple languages. In this example, the error messages are localized to Russian using the `localize.ru` function.

const Ajv = require('ajv');
const localize = require('ajv-i18n');

const ajv = new Ajv();
const schema = { type: 'object', properties: { foo: { type: 'string' } }, required: ['foo'], additionalProperties: false };
const validate = ajv.compile(schema);
const data = { bar: 2 };

const valid = validate(data);
if (!valid) {
  localize.ru(validate.errors); // Localize errors to Russian
  console.log(validate.errors);
}

Other packages similar to ajv-i18n

Keywords

ajv

FAQs

Package last updated on 08 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts