Skip to content

Commit

Permalink
Merge 5f2387b into f77af0a
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Mar 13, 2021
2 parents f77af0a + 5f2387b commit 38db8e6
Show file tree
Hide file tree
Showing 27 changed files with 1,337 additions and 1,131 deletions.
48 changes: 48 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const jsConfig = require("@ajv-validator/config/.eslintrc_js")

module.exports = {
env: {
es6: true,
node: true,
},
overrides: [
{
...jsConfig,
rules: {
semi: [2, "never"],
},
},
],
}

// extends: eslint:recommended
// env:
// node: true
// browser: true
// parserOptions:
// ecmaVersion: 2018
// rules:
// block-scoped-var: 2
// callback-return: 2
// curly: [2, multi-or-nest, consistent]
// dot-location: [2, property]
// dot-notation: 2
// indent-legacy: [2, 2, SwitchCase: 1]
// linebreak-style: [2, unix]
// new-cap: 2
// no-console: [2, allow: [warn, error]]
// no-else-return: 2
// no-eq-null: 2
// no-fallthrough: 2
// no-invalid-this: 2
// no-return-assign: 2
// no-shadow: 1
// no-trailing-spaces: 2
// no-use-before-define: [2, nofunc]
// quotes: [2, single, avoid-escape]
// semi: [2, always]
// strict: [2, global]
// valid-jsdoc: [2, requireReturn: false]
// no-control-regex: 0
// no-useless-escape: 2
// no-tabs: 2
30 changes: 0 additions & 30 deletions .eslintrc.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ node_modules

# Compiled templates
localize/**/*.js
!localize/index.js

# Browserified tests
.browser
Expand Down
8 changes: 7 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
[submodule "spec/JSON-Schema-Test-Suite"]
path = spec/JSON-Schema-Test-Suite
url = https://github.com/json-schema/JSON-Schema-Test-Suite.git
[submodule "spec/json-typedef-spec"]
path = spec/json-typedef-spec
url = https://github.com/jsontypedef/json-typedef-spec.git
[submodule "spec/ajv-keywords"]
path = spec/ajv-keywords
url = https://github.com/epoberezkin/ajv-keywords.git
url = https://github.com/ajv-validator/ajv-keywords.git
[submodule "spec/ajv-formats"]
path = spec/ajv-formats
url = https://github.com/ajv-validator/ajv-formats
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
spec/JSON-Schema-Test-Suite
spec/json-typedef-spec
spec/ajv-keywords
spec/ajv-keywords
.browser
coverage
bundle
.nyc_output
localize
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

125 changes: 59 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,52 @@
# ajv-i18n

Internationalised error messages for [Ajv](https://github.com/epoberezkin/ajv) - currently the fastest JSON-Schema validator
Internationalised error messages for [Ajv](https://github.com/ajv-validator/ajv) - superfast JSON validator for JSON Schema and JSON Type Definition.

[![Build Status](https://travis-ci.org/ajv-validator/ajv-i18n.svg?branch=master)](https://travis-ci.org/ajv-validator/ajv-i18n)
[![npm](https://img.shields.io/npm/v/ajv-i18n.svg)](https://www.npmjs.com/package/ajv-i18n)
[![Coverage Status](https://coveralls.io/repos/github/ajv-validator/ajv-i18n/badge.svg?branch=master)](https://coveralls.io/github/ajv-validator/ajv-i18n?branch=master)
[![Gitter](https://img.shields.io/gitter/room/ajv-validator/ajv.svg)](https://gitter.im/ajv-validator/ajv)


## Supported locales

|locale|language |contributor|draft-04|draft-06<sup>\*</sup>|draft-07<sup>\*\*</sup>|
|------|:-------:|:---------:|:------:|:------:|:------:|
|🇬🇧 en|English | ||||
|AR ar|Arabic |[Mahmoud-Mardeni](https://github.com/Mahmoud-Mardeni)||||
|CA ca|Catalan |[alexandreec](https://github.com/alexandreec)||||
|🇨🇿 cz|Czech |[kiskovacs](https://github.com/kiskovacs)<br>[NAM0007](https://github.com/NAM0007)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|
|🇩🇪 de|German |[jmtoball](https://github.com/jmtoball)<br>[gflohr](https://github.com/gflohr)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|
|🇪🇸 es|Spanish |[jpablom](https://github.com/jpablom)||||
|🇫🇷 fr|French |[monlouisj](https://github.com/monlouisj)<br>[Telokis](https://github.com/Telokis)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|
|🇭🇺 hu|Hungarian|[szilveszter9](https://github.com/szilveszter9)||-|-|
|🇮🇩 id|Indonesian|[Eko Eryanto](https://github.com/ekoeryanto)||||
|🇮🇹 it|Italian |[jasoniangreen](https://github.com/jasoniangreen)<br>[lucacorti](https://github.com/lucacorti)|✓<br>&nbsp;|<br>✓|<br>✓|
|🇯🇵 ja|Japanese |[gilgongo](https://github.com/gilgongo)||-|-|
|🇰🇷 ko|Korean |[MinByeongDon](https://github.com/MinByeongDon)||||
|🇳🇴 nb|Norwegian bokmål|[mtramm](https://github.com/mtramm)|||-|
|🇳🇱 nl|Dutch |[pimlie](https://github.com/pimlie)<br>[niekvb](https://github.com/niekvb)||||
|🇵🇱 pl|Polish |[danielzurawski](https://github.com/danielzurawski)||-|-|
|🇧🇷 pt-BR|Português - Brasil|[marcosrava](https://github.com/marcosrava)<br>[ggondim](https://github.com/ggondim)||||
|🇷🇺 ru|Russian | ||||
|🇸🇰 sk|Slovak |[kiskovacs](https://github.com/kiskovacs)|||-|
|🇸🇪 sv|Swedish |[limmen](https://github.com/Limmen)|||-|
|🇹🇭 th|Thai |[encX](https://github.com/encX)||||
|🇨🇳 zh|Chinese |[jinzhubaofu](https://github.com/jinzhubaofu)<br>[leuction](https://github.com/leuction)|✓<br>&nbsp;|<br>✓|<br>✓|
|🇹🇼 zh-TW|Chinese - Taiwan|[minipai](https://github.com/minipai)||||


<sup>\*</sup> added boolean schema, keywords `const`, `contains`, `propertyNames`

<sup>\*\*</sup> added keywords `if`/`then`/`else`
|locale|language |contributor|draft-04|draft-06<sup>1</sup>|draft-07<sup>2</sup>|draft<br>2019-09<br>2020-12<sup>3</sup>|JTD<sup>4</sup>
|------|:-------:|:---------:|:------:|:------:|:------:|:------:|:------:|
|🇬🇧 en|English | ||||||
|AR ar|Arabic |[Mahmoud-Mardeni](https://github.com/Mahmoud-Mardeni)||||-|-|
|CA ca|Catalan |[alexandreec](https://github.com/alexandreec)||||-|*|
|🇨🇿 cs|Czech |[kiskovacs](https://github.com/kiskovacs)<br>[NAM0007](https://github.com/NAM0007)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|-|*|
|🇩🇪 de|German |[jmtoball](https://github.com/jmtoball)<br>[gflohr](https://github.com/gflohr)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|-|*|
|🇪🇸 es|Spanish |[jpablom](https://github.com/jpablom)||||-|*|
|🇫🇷 fr|French |[monlouisj](https://github.com/monlouisj)<br>[Telokis](https://github.com/Telokis)|✓<br>&nbsp;|✓<br>&nbsp;|<br>✓|-|*|
|🇭🇺 hu|Hungarian|[szilveszter9](https://github.com/szilveszter9)||-|-|-|*|
|🇮🇩 id|Indonesian|[ekoeryanto](https://github.com/ekoeryanto)||||-|*|
|🇮🇹 it|Italian |[jasoniangreen](https://github.com/jasoniangreen)<br>[lucacorti](https://github.com/lucacorti)|✓<br>&nbsp;|<br>✓|<br>✓|-|*|
|🇯🇵 ja|Japanese |[gilgongo](https://github.com/gilgongo)||-|-|-|*|
|🇰🇷 ko|Korean |[MinByeongDon](https://github.com/MinByeongDon)||||-|*|
|🇳🇴 nb|Norwegian bokmål|[mtramm](https://github.com/mtramm)|||-|-|*|
|🇳🇱 nl|Dutch |[pimlie](https://github.com/pimlie)<br>[niekvb](https://github.com/niekvb)||||-|*|
|🇵🇱 pl|Polish |[danielzurawski](https://github.com/danielzurawski)||-|-|-|*|
|🇧🇷 pt-BR|Português - Brasil|[marcosrava](https://github.com/marcosrava)<br>[ggondim](https://github.com/ggondim)||||-|*|
|🇷🇺 ru|Russian | ||||||
|🇸🇰 sk|Slovak |[kiskovacs](https://github.com/kiskovacs)|||-|-|*|
|🇸🇪 sv|Swedish |[limmen](https://github.com/Limmen)|||-|-|*|
|🇹🇭 th|Thai |[encX](https://github.com/encX)||||-|*|
|🇨🇳 zh|Chinese |[jinzhubaofu](https://github.com/jinzhubaofu)<br>[leuction](https://github.com/leuction)|✓<br>&nbsp;|<br>✓|<br>✓|-|*|
|🇹🇼 zh-TW|Chinese - Taiwan|[minipai](https://github.com/minipai)||||-|*|


<sup>1</sup> added boolean schema, keywords `const`, `contains`, `propertyNames`

<sup>2</sup> added keywords `if`/`then`/`else`

<sup>3</sup> added keywords `unevaluatedProperties`, `unevaluatedItems`, `dependentRequired`

<sup>4</sup> 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:
Expand All @@ -51,52 +55,46 @@ Using npm:
npm install ajv-i18n
```

Using bower:

```
bower install ajv-i18n
cd bower_components/ajv-i18n
npm install && npm run bundle-all
```

## Usage

In node:

```javascript
var Ajv = require('ajv'); // version >= 2.0.0
var localize = require('ajv-i18n');
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")

// option `i18n` is required for this package to work
var ajv = Ajv({ allErrors: true });
var validate = ajv.compile(schema);
var valid = validate(data);
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' }));
// 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 in browser (with browserify):
To require only necessary locales (e.g., with browserify):

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

or

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

See [Ajv docs](https://github.com/epoberezkin/ajv) for more information.

See [Ajv docs](https://github.com/ajv-validator/ajv) for more information.

## Tests

Expand All @@ -106,13 +104,11 @@ git submodule update --init
npm test
```


## Contributing

Functions that localize error messages are generated using doT templates in [messages](https://github.com/epoberezkin/ajv-i18n/tree/master/messages/index.js) and [localize.jst](https://github.com/epoberezkin/ajv-i18n/tree/master/localize/localize.jst) template. Templates are precompiled so doT is not a run-time dependency.

`npm run build` - compiles functions to [localize](https://github.com/epoberezkin/ajv/tree/master/localize) folder.
Functions that localize error messages are generated using doT template [localize.jst](https://github.com/ajv-validator/ajv-i18n/tree/master/localize/localize.jst), [JSON Schema messages](https://github.com/ajv-validator/ajv-i18n/tree/master/messages/index.js) and [JSON Type Definition messages](https://github.com/ajv-validator/ajv-i18n/tree/master/messages/jtd.js). Templates are pre-compiled, so doT is not a run-time dependency.

`npm run build` - compiles functions to [localize](https://github.com/ajv-validator/ajv/tree/master/localize) folder.

## Contributors of locales

Expand Down Expand Up @@ -144,19 +140,16 @@ Functions that localize error messages are generated using doT templates in [mes
[![niekvb](https://avatars3.githubusercontent.com/u/37668320?s=40&v=4)](https://github.com/niekvb "niekvb")
[![NAM0007](https://avatars1.githubusercontent.com/u/47188486?s=40&v=4)](https://github.com/NAM0007 "NAM0007")


## Enterprise support

ajv-i18n package is a part of [Tidelift enterprise subscription](https://tidelift.com/subscription/pkg/npm-ajv-i18n?utm_source=npm-ajv-i18n&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - 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](https://tidelift.com/security).
Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.


## License

[MIT](https://github.com/epoberezkin/ajv-i18n/blob/master/LICENSE)
[MIT](https://github.com/ajv-validator/ajv-i18n/blob/master/LICENSE)
27 changes: 0 additions & 27 deletions bower.json

This file was deleted.

Loading

0 comments on commit 38db8e6

Please sign in to comment.