Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何修改validate插件错误提示为中文? #1064

Closed
skyyangpeng opened this issue Jun 16, 2017 · 3 comments
Closed

如何修改validate插件错误提示为中文? #1064

skyyangpeng opened this issue Jun 16, 2017 · 3 comments

Comments

@skyyangpeng
Copy link

//表单数据验证规则--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改成中文,请问在哪里改呢?或者怎么配置?

@jackhutu
Copy link

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

@popomore
Copy link
Member

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

@atian25
Copy link
Member

atian25 commented Jun 19, 2017

#589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants