validate.js
validate.js copied to clipboard
Support multi locale support
Schedule
update test < pending update document < pending (because my english not good)
Support multi locale support by flow step:
Setup
// set locale
validate.options.locale = 'vi'; //default en
// set locale string
validate.setLocale({vi: {email: {notValid: '^%{value} không phải là một địa chỉ email hợp lệ.'}}});
Example:
var constraints = {
email: {
email: true,
length: {maximum: 3}
}
};
console.log(validate({email: 'validatejs'}, constraints));
// output
// { email:
// [ 'Email is not a valid email',
// 'Email is too long (maximum is 3 characters)' ] }
validate.options = {locale: 'vi'};
validate.setLocale({vi: {email: {notValid: '^%{value} không phải là một địa chỉ email hợp lệ.'}}});
console.log(validate({email: 'validatejs'}, constraints));
// output
// { email:
// [ 'validatejs org không phải là một địa chỉ email hợp lệ.',
// 'Email is too long (maximum is 3 characters)' ] }
var constraints = {
email: {
email: {message: {vi: '^%{value} không phải là một địa chỉ email hợp lệ.'}},
length: {maximum: 3}
}
};
console.log(validate({email: 'validatejs'}, constraints));
// output, because not en locale not defined
// { email: [ 'Email is too long (maximum is 3 characters)' ] }
// validate.setLocale({vi: {email: {notValid: '^%{value} không phải là một địa chỉ email hợp lệ.'}}});
validate.options = {locale: 'vi'};
console.log(validate({email: 'validatejs'}, constraints));
// output
// { email:
// [ 'validatejs không phải là một địa chỉ email hợp lệ.',
// 'Email is too long (maximum is 3 characters)' ] }
Coverage decreased (-1.5%) to 98.542% when pulling eedfef490f0ca2e6a50ffcdedfc19ab6811e931d on thinhbuzz:master into cccc345aa70cda2a59bccdbc240ffd52b7528bda on ansman:master.
Hi @thinhbuzz, could you fix branch conflicts?
I would like to ask @ansman to merge your change, which is very useful.
Thank you both.
Hi @thinhbuzz, could you fix branch conflicts?
I would like to ask @ansman to merge your change, which is very useful.
Thank you both.
I will try resolve conflicts and update PR tonight.