-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Feature] Vue i18n integration #1007
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1007 +/- ##
==========================================
+ Coverage 98.8% 98.85% +0.04%
==========================================
Files 47 48 +1
Lines 1340 1395 +55
Branches 442 451 +9
==========================================
+ Hits 1324 1379 +55
Misses 15 15
Partials 1 1
Continue to review full report at Codecov.
|
393ce7b
to
6f9f095
Compare
json structure doesn't seem to include anything about custom validation messages per field name
|
@nkwinder should work the same, I actually omitted the custom, dateFormat, and _default properties. Full draft will be documented soon after supporting as many features as VueI18n provides. |
How do I know the current locale from within getMessage? |
getMessage is not for localization, it only works for simple usecases where your app has a single language supported, otherwise use the localization API instead. |
Overview
VeeValidate uses a custom dictionary implementation with many features that include, messages, attributes and date formats. While it works fine for most projects, it causes redundant localization since
VueI18n
plugin is the go to plugin for Vue when it comes to localization and it offers all of whatvee-validate
needs and more.This PR aims lets
vee-validate
use thevue-i18n
dictionary implementation instead of the custom one, meaning your locales will only live inI18n
plugin instance instead of both of them.This feature is
opt-in
, you will need to provide i18n instance to the config.Converting Old Localization Files
This plugin also allows transforming the
vee-validate
locales to thevue-i18n
which should help you get started quickly.Here is the structure that
vee-validate
expects inside ani18n
locale:This PR also introduces the ability to create a custom localization driver, if you have more advanced needs.
Breaking Changes
This PR removes the ability to define localized messages when calling
extend
on the validator, you should prepare your messages before hand to be merged in the validator before using the rule. So now you can only provide either a validator function directly or an object containingvalidator
andgetMessage
methods.Caveats
The
vee-validate
localization API likelocalize
method or thelocale
setter will no longer have an effect as the localization is being entirely generated fromvue-i18n
plugin. However you can still merge locale and set messages/attributes using thedictionary
property.Some rules like
length
have different messages depending on the parameters used in the validation run, so you might want to change the message to be more general.This PR is still under progress and may change any mentioned details at anytime.