-
Notifications
You must be signed in to change notification settings - Fork 824
feat: add support i18n #730
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
Conversation
@NoNameProvided ping) |
New Crowdin updates
New Crowdin updates
Added support integrations with https://crowdin.com/ for manual simplified update translates Added more examples of usages Basic set custom messages import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';
class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}
const RU_I18N_MESSAGES = {
...I18N_MESSAGES,
'$property must be equal to $constraint1': '$property должно быть равно $constraint1',
};
const model = new MyClass();
validator.validate(model, messages: RU_I18N_MESSAGES).then(errors => {
console.log(errors[0].constraints);
// out: title должно быть равно test
}); Load from file import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';
import { readFileSync } from 'fs';
import { resolve } from 'path';
class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}
const RU_I18N_MESSAGES = JSON.parse(readFileSync(resolve(__dirname, './node_modules/class-validator/i18n/ru.json')).toString());
const model = new MyClass();
validator.validate(model, messages: RU_I18N_MESSAGES).then(errors => {
console.log(errors[0].constraints);
// out: title должен быть равен test
}); With override import { IsOptional, Equals, Validator, I18N_MESSAGES } from 'class-validator';
class MyClass {
@IsOptional()
@Equals('test')
title: string = 'bad_value';
}
Object.assign(I18N_MESSAGES, {
'$property must be equal to $constraint1': '$property должно быть равно $constraint1',
});
const model = new MyClass();
validator.validate(model).then(errors => {
console.log(errors[0].constraints);
// out: title должно быть равно test
}); |
New Crowdin updates
Hi, @NoNameProvided I want to use this feature in https://github.com/EndyKaufman/ngx-dynamic-form-builder, please review this PR :( |
I create new clean PR for this changes #743 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
Example of usage
Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passesFixes
fixes #[issue number], fixes #[issue number]