-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[RFC] egg-validate support i18n and auto load rule file #1672
Comments
addRule('json', (rule, value, obj) => {
return rule.__('error message');
}); |
thinking about drop |
推荐一下 property-validator |
Parameter seems hard to pass a context-level translate fn @dead-horse any suggest ? |
这个好了?急需多语言支持 |
In enterprise-level development, data validation is very necessary and we hope to do so as soon as possible. |
@monkeym4ster new version of https://github.com/eggjs/egg-validate/blob/master/app.js#L27 |
@atian25 So how can I translate error messages using gettext or __ method? // in config.[env].js
exports.validate = {
translate: error => {
// something here but I cannot use ctx.__
}
}; Or do I need to configure a brand new |
@JoaoCnh you could config it by https://github.com/eggjs/egg-validate#configurations cc @dead-horse |
@atian25 I realised that and I know that Parameter as a translate method. My problem is actually the translation. We should translate according to the locale from the request and in said method we have no access to context. So we can't even use gettext. EDIT: I know yup as very good schema validating lib and it even lets you define labels for each property. See [here] an example of yup for egg (https://github.com/seekcx/egg-yup) |
Background
Currently, egg-validate don't support
i18n
:Proposal
i18n
egg-validate
will use egg-i18n asoptionalDependencies
translate
toctx.gettext
which provide byegg-i8n
rule file
app/validate/**/*.js
, and register toapp.validator.addRule(type, fn)
The text was updated successfully, but these errors were encountered: