Localization

English is built in and twenty translations ship with the package. Messages are whole-sentence templates with real plural forms, so a translator can put the number where their language needs it instead of inheriting English word order.

Bundled languages

CodeLanguageCodeLanguageCodeLanguageCodeLanguage
arArabiccaCatalancsCzechdaDanish
deGermanesSpanishfaPersianfrFrench
itItaliankaGeorgiankoKoreannlDutch
noNorwegianplPolishptPortugueseroRomanian
ruRussiansvSwedishtrTurkishviVietnamese

Loading a language

JavaScript
$.validate({ lang: 'sv' });     // fetched at runtime, like a module
JavaScript
import 'jquery-form-validator/lang/sv';   // registered up front, no request

$.validate();

Overriding individual messages

The language option is merged over whichever catalogue is active, so you can adjust a handful of strings without maintaining a whole file.

JavaScript
$.validate({
  language: {
    requiredField: 'We need this one',
    badEmail: 'That does not look like an email address',
    errorTitle: 'Please check the following'
  }
});

Message templates

Messages that carry a number used to be assembled by concatenating two fragments around it, which pins every language to English word order and cannot express plural forms. Since 3.0 they are whole sentences with a {0} placeholder:

JavaScript
// Before 3.0 — two fragments glued around a number
lengthTooShortStart: 'The input value is shorter than ',
lengthBadEnd: ' characters'

// From 3.0 — one sentence, with plural forms
lengthTooShort: {
  one:   'The input value is shorter than {0} character',
  other: 'The input value is shorter than {0} characters'
}

Plural category selection goes through Intl.PluralRules, so languages with more than two forms are handled properly rather than being forced into item(s).

JavaScript
$.validate({
  lang: 'pl',
  language: {
    groupCheckedTooFew: {
      one:   'Wybierz co najmniej {0} opcję',
      few:   'Wybierz co najmniej {0} opcje',
      many:  'Wybierz co najmniej {0} opcji',
      other: 'Wybierz co najmniej {0} opcji'
    }
  }
});
Nothing broke

The old fragment keys are still present in every bundled language and are still honoured. If a template is absent the fragments are concatenated exactly as before, so a language override that only sets the old keys keeps working unchanged.

Which messages take a count

Template keyFragments it replaces
lengthBadRangelengthBadStart + lengthBadEnd
lengthTooShortlengthTooShortStart + lengthBadEnd
lengthTooLonglengthTooLongStart + lengthBadEnd
groupCheckedRangegroupCheckedRangeStart + groupCheckedEnd
groupCheckedTooFewgroupCheckedTooFewStart + groupCheckedEnd
groupCheckedTooManygroupCheckedTooManyStart + groupCheckedEnd
badNumberOfSelectedOptionsbadNumberOfSelectedOptionsStart + ...End
Bundled translations are flat strings

The templates in the twenty bundled languages were composed mechanically from the fragments each file already contained, so today's output is identical to before. They are flat strings rather than plural objects, because a trailing fragment such as " tecken" does not reveal what the singular should be. Adding proper plural forms for your language is a welcome contribution.

Message keys

Every key you can override. Anything absent falls back to English.

General

KeyDefault
errorTitleForm submission failed!
requiredFieldThis is a required field
requiredFieldsYou have not answered all required fields
badCustomValThe input value is incorrect
notConfirmedInput values could not be confirmed

Formats

KeyDefault
badEmailYou have not given a correct e-mail address
badUrlThe input value is not a correct URL
badDomainIncorrect domain value
badIntThe input value was not a correct number
badDateYou have not given a correct date
badTimeYou have not given a correct time
badTelephoneYou have not given a correct phone number
badAlphaNumericThe input value can only contain alphanumeric characters
badAlphaNumericExtra and
andSpaces and spaces

Security

KeyDefault
badStrengthThe password isn't strong enough
badBreachedPasswordThis password has appeared in a known data breach. Please choose a different one.
badCreditCardThe credit card number is not correct
badCVVThe CVV number was not correct
badSecurityAnswerYou have not given a correct answer to the security question
badSecurityNumberYour social security number was incorrect
badreCaptchaPlease confirm that you are not a bot
passwordComplexityStartPassword must contain at least
passwordComplexityUppercaseInfo uppercase letter(s)
passwordComplexityLowercaseInfo lowercase letter(s)
passwordComplexitySpecialCharsInfo special character(s)
passwordComplexityNumericCharsInfo numeric character(s)

Files

KeyDefault
wrongFileSizeThe file you are trying to upload is too large (max %s)
wrongFileTypeOnly files of type %s is allowed
wrongFileDimIncorrect image dimensions,
imageTooTallthe image can not be taller than
imageTooWidethe image can not be wider than
imageTooSmallthe image was too small
imageRatioNotAcceptedImage ratio is not be accepted

Banking and national formats

KeyDefault
badIbanInvalid IBAN number
badBicInvalid BIC/SWIFT code
badSepaInvalid SEPA account number
badUKVatAnswerIncorrect UK VAT Number
badUKNinIncorrect UK NIN
badUKUtrIncorrect UK UTR Number
badBrazilCPFAnswerThe CPF entered is invalid
badBrazilCEPAnswerThe CEP entered is invalid
badBrazilTelephoneAnswerThe phone number entered is invalid
badPlPeselThe PESEL entered is invalid
badPlNipThe NIP entered is invalid
badPlRegonThe REGON entered is invalid

Numbers

decimalSeparator takes an 'auto' setting that reads the separator from the browser locale through Intl.NumberFormat.

JavaScript
$.validate({ decimalSeparator: 'auto' });
It is opt-in, and the default is still a full stop

Deliberately. A form that posts to a server expecting 1.5 should not silently start accepting 1,5 because a visitor's browser is set to German. What matters is your site's locale, which the library has no way of knowing.

For display, the localeNumberFormat sanitizer formats through Intl.NumberFormat with no third-party dependency:

HTML
<input data-sanitize="localeNumberFormat"
       data-sanitize-locale="de-DE"
       data-sanitize-number-options='{"minimumFractionDigits":2}'>

Adding a language

A language file replaces $.formUtils.LANG wholesale. Copy an existing one from src/lang/ as a starting point.

form-validator/lang/xx.js
(function ($) {
  $.formUtils.registerLoadedModule('lang/xx');

  $.formUtils.LANG = {
    errorTitle: '…',
    requiredField: '…',
    badEmail: '…',

    // Whole-sentence template; {0} is the number.
    lengthTooShort: {
      one:   '…{0}…',
      other: '…{0}…'
    }
    // …
  };
})(jQuery);

Formatting helpers

The same helpers the plugin uses are available for your own validators.

JavaScript
$.formUtils.formatMessage('between {0} and {1}', [2, 8]);
// "between 2 and 8"

$.formUtils.formatMessage(
  {one: '{0} item', other: '{0} items'}, [3], 3
);
// "3 items"

$.formUtils.locale();                    // "en-GB"
$.formUtils.localeDecimalSeparator();    // "."