Skip to content
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

Provide export of supported locales and/or a 'isLocaleSupported' function #657

Closed
mikereinhold opened this issue May 3, 2017 · 2 comments

Comments

@mikereinhold
Copy link

When trying to write validations for multiple locales, it would be nice to be able to check if validation is supported for the locale in question. Currently the locale specific validation functions just return false if an unsupported locale is provided, so if I want to differentiate between a failed validation and an unknown locale then I have to cross-reference the list of supported locales for that validator. Right now, none of these supported locales lists are exported, so it would have to be handled entirely by clietn code and would end up being stale, etc.

The ideal option might be to throw "Unsupported locale" or something similar instead of just returning false, though that would break backwards compatibility for existing users...

Alternatively, adding a way for consumers of validator.js to check which locales are supported for validation would allow people to intelligently handle these failures.

If the list of supported locales is consistent between all locale specific validation functions, a simple isLocaleSupported validator may be sufficient. Otherwise, providing exports of the different supported locale lists would be a decent start.

@chriso
Copy link
Collaborator

chriso commented Jun 22, 2017

The ideal option might be to throw "Unsupported locale" or something similar instead of just returning false, though that would break backwards compatibility for existing users...

I think this is the way to go, and I'd be happy to accept a PR with this change. It'd be a breaking change but I can bump the major as necessary.

@chriso
Copy link
Collaborator

chriso commented Jul 7, 2017

Fixed by 56e7d33. This will be out in the next major release.

@chriso chriso closed this as completed Jul 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants