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
| Code | Language | Code | Language | Code | Language | Code | Language |
|---|---|---|---|---|---|---|---|
ar | Arabic | ca | Catalan | cs | Czech | da | Danish |
de | German | es | Spanish | fa | Persian | fr | French |
it | Italian | ka | Georgian | ko | Korean | nl | Dutch |
no | Norwegian | pl | Polish | pt | Portuguese | ro | Romanian |
ru | Russian | sv | Swedish | tr | Turkish | vi | Vietnamese |
Loading a language
$.validate({ lang: 'sv' }); // fetched at runtime, like a moduleimport '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.
$.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:
// 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).
$.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'
}
}
});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 key | Fragments it replaces |
|---|---|
lengthBadRange | lengthBadStart + lengthBadEnd |
lengthTooShort | lengthTooShortStart + lengthBadEnd |
lengthTooLong | lengthTooLongStart + lengthBadEnd |
groupCheckedRange | groupCheckedRangeStart + groupCheckedEnd |
groupCheckedTooFew | groupCheckedTooFewStart + groupCheckedEnd |
groupCheckedTooMany | groupCheckedTooManyStart + groupCheckedEnd |
badNumberOfSelectedOptions | badNumberOfSelectedOptionsStart + ...End |
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
| Key | Default |
|---|---|
errorTitle | Form submission failed! |
requiredField | This is a required field |
requiredFields | You have not answered all required fields |
badCustomVal | The input value is incorrect |
notConfirmed | Input values could not be confirmed |
Formats
| Key | Default |
|---|---|
badEmail | You have not given a correct e-mail address |
badUrl | The input value is not a correct URL |
badDomain | Incorrect domain value |
badInt | The input value was not a correct number |
badDate | You have not given a correct date |
badTime | You have not given a correct time |
badTelephone | You have not given a correct phone number |
badAlphaNumeric | The input value can only contain alphanumeric characters |
badAlphaNumericExtra | and |
andSpaces | and spaces |
Security
| Key | Default |
|---|---|
badStrength | The password isn't strong enough |
badBreachedPassword | This password has appeared in a known data breach. Please choose a different one. |
badCreditCard | The credit card number is not correct |
badCVV | The CVV number was not correct |
badSecurityAnswer | You have not given a correct answer to the security question |
badSecurityNumber | Your social security number was incorrect |
badreCaptcha | Please confirm that you are not a bot |
passwordComplexityStart | Password must contain at least |
passwordComplexityUppercaseInfo | uppercase letter(s) |
passwordComplexityLowercaseInfo | lowercase letter(s) |
passwordComplexitySpecialCharsInfo | special character(s) |
passwordComplexityNumericCharsInfo | numeric character(s) |
Files
| Key | Default |
|---|---|
wrongFileSize | The file you are trying to upload is too large (max %s) |
wrongFileType | Only files of type %s is allowed |
wrongFileDim | Incorrect image dimensions, |
imageTooTall | the image can not be taller than |
imageTooWide | the image can not be wider than |
imageTooSmall | the image was too small |
imageRatioNotAccepted | Image ratio is not be accepted |
Banking and national formats
| Key | Default |
|---|---|
badIban | Invalid IBAN number |
badBic | Invalid BIC/SWIFT code |
badSepa | Invalid SEPA account number |
badUKVatAnswer | Incorrect UK VAT Number |
badUKNin | Incorrect UK NIN |
badUKUtr | Incorrect UK UTR Number |
badBrazilCPFAnswer | The CPF entered is invalid |
badBrazilCEPAnswer | The CEP entered is invalid |
badBrazilTelephoneAnswer | The phone number entered is invalid |
badPlPesel | The PESEL entered is invalid |
badPlNip | The NIP entered is invalid |
badPlRegon | The REGON entered is invalid |
Numbers
decimalSeparator takes an 'auto' setting that reads the separator from
the browser locale through Intl.NumberFormat.
$.validate({ decimalSeparator: 'auto' });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:
<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.
(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.
$.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(); // "."