@vee-validate/i18n
TypeScript icon, indicating that this package has built-in type declarations

4.15.0 • Public • Published

@vee-validate/i18n

Localization module for vee-validate

What's this

VeeValidate v4 breaks up the parts that made it a popular solution for form validation into it isolated parts. The core vee-validate package no longer includes logic for localization.

This is where this package comes in.

Installation

yarn add @vee-validate/i18n

# or with npm
npm install @vee-validate/i18n

Usage

import the localize() function from @vee-validate/i18n which returns a message generator function:

import { defineRule, configure } from 'vee-validate';
import { required } from '@vee-validate/rules';
import { localize } from '@vee-validate/i18n';

// Define the rule globally
defineRule('required', required);

configure({
  // Generates an English message locale generator
  generateMessage: localize('en', {
    messages: {
      required: 'This field is required',
    },
  }),
});

If you have multiple locales in your application, you can add them like this:

import { defineRule, configure } from 'vee-validate';
import { required } from '@vee-validate/rules';
import { localize } from '@vee-validate/i18n';

// Define the rule globally
defineRule('required', required);

configure({
  generateMessage: localize({
    en: {
      messages: {
        required: 'This field is required',
      },
    },
    ar: {
      messages: {
        required: 'هذا الحقل مطلوب',
      },
    },
  }),
});

You can change the locale using setLocale function exported by the @vee-validate/i18n anywhere in your application:

import { setLocale } from '@vee-validate/i18n';

setLocale('ar');

Available Languages

To save you a lot of time translating @vee-validate/rules messages to your language, the awesome community around vee-validate already contributed over 40+ languages that you can use directly in your application and get started quickly. The localized files include localized messages for all the global rules provided by @vee-validate/rules package.

You can import the locales from their JSON directory like this:

import { configure } from 'vee-validate';
import { localize } from '@vee-validate/i18n';
import en from '@vee-validate/i18n/dist/locale/en.json';
import ar from '@vee-validate/i18n/dist/locale/ar.json';

configure({
  generateMessage: localize({
    en,
    ar,
  }),
});

You can view a list of the available languages by checking the locale folder

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
4.5.0-alpha.60edge
4.5.0-alpha.20next-edge
4.15.04,006latest
4.5.870next
4.12.0-alpha.11alpha

Version History

VersionDownloads (Last 7 Days)Published
4.15.04,006
4.14.74,799
4.14.61,529
4.14.51
4.14.4179
4.14.3374
4.14.21
4.14.18
4.14.01
4.13.23,892
4.13.1559
4.13.0120
4.12.8325
4.12.796
4.12.61,292
4.12.51,475
4.12.4354
4.12.3140
4.12.21,646
4.12.15
4.12.042
4.12.0-alpha.11
4.12.0-alpha.00
4.11.81,698
4.11.779
4.11.686
4.11.50
4.11.40
4.11.343
4.11.239
4.11.1157
4.11.03
4.10.91
4.10.8709
4.10.734
4.10.61
4.10.541
4.10.41
4.10.32
4.10.247
4.10.110
4.10.00
4.9.6234
4.9.5161
4.9.42
4.9.374
4.9.20
4.9.11
4.9.0174
4.8.6194
4.8.50
4.8.372
4.8.217
4.8.126
4.8.00
4.7.41,046
4.7.3657
4.7.21,178
4.7.168
4.7.037
4.6.1042
4.6.90
4.6.80
4.6.737
4.6.620
4.6.59
4.6.44
4.6.30
4.6.2259
4.6.17
4.6.06
4.5.11238
4.5.109
4.5.9180
4.5.870
4.5.7181
4.5.67
4.5.50
4.5.41
4.5.37
4.5.213
4.5.10
4.5.00
4.4.110
4.5.0-alpha.60
4.4.100
4.5.0-alpha.50
4.5.0-alpha.40
4.4.90
4.4.80
4.5.0-alpha.30
4.4.713
4.5.0-alpha.20
4.4.61
4.5.0-alpha.10
4.4.52
4.4.40
4.5.0-alpha.00
4.4.30
4.4.20
4.4.10
4.4.00
4.4.0-alpha.20
4.4.0-alpha.10
4.4.0-alpha.00
4.3.65
4.3.50
4.3.40
4.3.30
4.3.20
4.3.10
4.3.00
4.2.40
4.2.30
4.2.20
4.2.10
4.2.00
4.1.20106
4.1.190
4.1.170
4.1.063
4.0.30
4.0.2215
4.0.13
4.0.00
4.0.0-beta.20
4.0.0-beta.10
4.0.0-beta.00
4.0.0-alpha.70
4.0.0-alpha.60
4.0.0-alpha.50
4.0.0-alpha.40
4.0.0-alpha.30
4.0.0-alpha.20
4.0.0-alpha.10

Package Sidebar

Install

npm i @vee-validate/i18n

Weekly Downloads

29,235

Version

4.15.0

License

MIT

Unpacked Size

140 kB

Total Files

64

Last publish

Collaborators

  • logaretm