ajv-i18n
Ajv 国际化错误消息插件。
支持国家和地区
locale | language | contributor | draft-04 | draft-06* | draft-07** |
---|---|---|---|---|---|
English | ✓ | ✓ | ✓ | ||
AR ar | Arabic | Mahmoud-Mardeni | ✓ | ✓ | ✓ |
Czech | kiskovacs | ✓ | ✓ | - | |
German | jmtoball gflohr | ✓ | ✓ | ✓ | |
Spanish | jpablom | ✓ | - | - | |
French | monlouisj Telokis | ✓ | ✓ | ✓ | |
Hungarian | szilveszter9 | ✓ | - | - | |
Indonesian | Eko Eryanto | ✓ | ✓ | ✓ | |
Italian | jasoniangreen lucacorti | ✓ | ✓ | ✓ | |
Japanese | gilgongo | ✓ | - | - | |
Korean | MinByeongDon | ✓ | ✓ | ✓ | |
Norwegian bokmål | mtramm | ✓ | ✓ | - | |
Dutch | pimlie | ✓ | ✓ | ✓ | |
Polish | danielzurawski | ✓ | - | - | |
Português - Brasil | marcosrava | ✓ | ✓ | ✓ | |
Russian | ✓ | ✓ | ✓ | ||
Slovak | kiskovacs | ✓ | ✓ | - | |
Swedish | limmen | ✓ | ✓ | - | |
Thai | encX | ✓ | ✓ | ✓ | |
Chinese | jinzhubaofu leuction | ✓ | ✓ | ✓ | |
Chinese - Taiwan | minipai | ✓ | ✓ | ✓ |
安装
使用 npm
npm install ajv-i18n
1
使用 bower
bower install ajv-i18n
cd bower_components/ajv-i18n
npm install && npm run bundle-all
1
2
3
2
3
使用
在 node 中使用:
var Ajv = require('ajv'); // version >= 2.0.0
var localize = require('ajv-i18n');
// 配置项 `i18n` 是该插件工作的必要条件
var ajv = Ajv({ allErrors: true });
var validate = ajv.compile(schema);
var valid = validate(data);
if (!valid) {
// ru 指俄语
localize.ru(validate.errors);
// 所有错误和数据路径的字符串
console.log(ajv.errorsText(validate.errors, { separator: '\n' }));
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
在浏览器中只需要必要的语言环境(browserify):
var localize_ru = require('ajv-i18n/localize/ru');
1
或
var localize = {
en: require('ajv-i18n/localize/en'),
ru: require('ajv-i18n/localize/ru')
};
1
2
3
4
2
3
4
测试
npm install
git submodule update --init
npm test
1
2
3
2
3