-
Notifications
You must be signed in to change notification settings - Fork 12
Localization
jQuery Form Validate can be localized into many different languages. By default, English is used for success and failure messages. Custom language support, like extending other parts of the jQuery Form Validate plugin, is accomplished by extending the options object. This can be done in a global scope, or only for a particular form.
For example, if you wanted German messages you would first need to include this following piece of JavaScript on your page:
jQuery.extend(true, jQuery.fn.formvalidate.options.localization, {
de: {
failure: {
'default': '{0} ist ungültig.',
betweenNumeric: '{0} muss zwischen {2} und {3} liegen.',
date: '{0} ist kein gültiges Datum.',
email: '{1} ist keine gültige Email Adresse.',
numChars: '{0} muss aus genau {2} Zeichen bestehen.',
minChars: '{0} muss aus mindestens {2} Zeichen bestehen.',
maxChars: '{0} kann maximal {2} Zeichen haben.',
numOptions: 'Bitte genau {2} Optionen auswählen.',
minOptions: 'Bitte mindestens {2} Optionen auswählen.',
maxOptions: 'Bitte maximal {2} Optionen auswählen.',
'int': '{0} ist keine ganze Zahl(Integer)',
'float': '{0} ist keine gültige Nummer.',
required: '{0} ist ein Pflichtfeld.',
requiredIf: '{0} ist ein Pflichtfeld.',
lessThan: '{0} muss kleiner sein als {2}.',
greaterThan: '{0} muss größer sein als {2}.'
},
success: {
'default': '{0} ist gut.'
}
}
});
After you include the code above it gets merged into the default jQuery Form Validate options object. You can then either enable German messages globally or locally.
To make the messages for an individual form German you would need to set the language property to de.
$('#form-1').submit(function(e) {
e.preventDefault();
$(this).formvalidate({
language: 'de'
});
});
Alternatively, you could setup German language globally for all forms.
jQuery.extend(true, jQuery.fn.formvalidate.options, {
language: 'de'
});
You may notice that this code looks very similar to the way we included the German messages. That is because they all do the same thing: extend the main jQuery Form Validation options object.