Egg: 如何修改validate插件错误提示为中文?

Created on 16 Jun 2017  ·  3Comments  ·  Source: eggjs/egg

//表单数据验证规则--controller/uer.js
const createRule={
name:{type:'string',required: true, allowEmpty: false,min:5,max:32},
password:{type: 'password', required: true, allowEmpty: false, min: 6},
email:{type: 'email', required: true, allowEmpty: false}
};
//对表单数据进行校验
try{
ctx.validate(createRule);
}
catch(err){
ctx.body=err;
return;
}
打印出的error:
{"message":"Validation Failed","code":"invalid_param","errors":[{"message":"length should bigger than 5","code":"invalid","field":"name"},{"message":"should not be empty","code":"invalid","field":"password"}]}

我想把上面errors中的message改成中文,请问在哪里改呢?或者怎么配置?

Inactive egg-validate

Most helpful comment

确实需要自定义错误信息.

All 3 comments

确实需要自定义错误信息.

Parameter 支持 translate,不过 egg-validate 没传

Was this page helpful?
0 / 5 - 0 ratings