Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Support multi locale support #252

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Support multi locale support #252

wants to merge 7 commits into from

Conversation

thinhbuzz
Copy link

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)' ] }

@thinhbuzz thinhbuzz closed this Feb 5, 2018
@thinhbuzz thinhbuzz reopened this Apr 24, 2018
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.5%) to 98.542% when pulling eedfef4 on thinhbuzz:master into cccc345 on ansman:master.

@ansman ansman force-pushed the master branch 4 times, most recently from feffe94 to 40e06a1 Compare June 15, 2019 17:55
@rogervila
Copy link

Hi @thinhbuzz, could you fix branch conflicts?

I would like to ask @ansman to merge your change, which is very useful.

Thank you both.

@thinhbuzz
Copy link
Author

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.

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

Successfully merging this pull request may close these issues.

3 participants