drip-form-validator i18n.

drip-form-validator supports internationalization.
You can load locales and easily switch between them.

However, there are few locales that are still supported.
PR is welcomed.

Example

The following is an example of switching to Japanese.

import { Validator } from 'drip-form-validator';
import 'drip-form-validator/lib/locale/ja'; // Load locale file

Validator.setLocale('ja');

Definition of your locale

Please specify the message corresponding to the rule name.

Validator.defineLocale('localeName', {
  // `defaultMessage` is required field.
  defaultMessage: 'The {{field}} field is invalid.',

  // It is a normal designation method.
  // The key `field` will definitely come across.
  // Other parameters are parameters passed to the rule.
  alpha: 'The {{field}} may only contain letters.',

  // It is also possible to change the message according to the value type.
  between: {
    defaultMessage: 'The {{field}} must be between {{min}} and {{max}}.',
    string: 'The {{field}} must be between {{min}} and {{max}} characters.',
    array: 'The {{field}} must be between {{min}} and {{max}} items.',
  },

  // It is also possible to pass functions.
  ruleName: (field, value, params) => `The ${field} field value is ${value}, params = ${JSON.stringify(params, null, '  ')}`,
});

List of supported locales

  • English (en)
  • Japanese (ja)

results matching ""

    No results matching ""