protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

How do I set the language of error messages ?

Open JinPengCN opened this issue 3 years ago • 1 comments

In my project, I want to set the error message to Chinese.I use kratos validator middleware Here's the code:

// Validator is a validator middleware.
func Validator() middleware.Middleware {
	return func(handler middleware.Handler) middleware.Handler {
		return func(ctx context.Context, req interface{}) (reply interface{}, err error) {
			if v, ok := req.(validator); ok {
				if err := v.Validate(); err != nil {
					return nil, errors.BadRequest("VALIDATOR", err.Error())
				}
			}
			return handler(ctx, req)
		}
	}
}

I don't want to change the source code of kratos.so,what should I do. Now, I handled it myself.

if err := req.Validate(); err != nil {
		return nil, pb.ErrorParamError("参数错误")
	}

But I don't think this is the best way

JinPengCN avatar Jan 17 '22 08:01 JinPengCN

我有一个方法,你clone 一份最新的PGV,在模板里面把错误都改成中文,然后再make build 就可以了

habbyCP avatar Apr 11 '22 12:04 habbyCP