Make it possible to translate data-msg attribute
jquery-validate: 1.17i have a remote validator that return true or false. In my html markup i set data-msg-remote="duplicate"
replace duplicate with $.validator.messages.duplicate
it use the string duplicate
actually i use the errorPlacement function. But i would prefer to define a custom callback function where i translate the messages.
errorPlacement: function (error, element) {
var text = error.text();
if ($.validator.messages.hasOwnProperty(text)) {
error.text($.validator.messages[text]);
}
}
errorPlacement only works for first time. Better solution.
showErrors: function(errorMap, errorList) {
$.each(errorList, function (key, error) {
if ($.validator.messages.hasOwnProperty(error.message)) {
error.message = $.validator.messages[error.message];
}
});
this.defaultShowErrors();
},
we use a snippet like the following to translate error messages into DE:
$.extend($.validator.messages, {
required: "Dieses Feld ist ein Pflichtfeld.",
maxlength: $.validator.format("Geben Sie bitte maximal {0} Zeichen ein."),
minlength: $.validator.format("Geben Sie bitte mindestens {0} Zeichen ein."),
rangelength: $.validator.format("Geben Sie bitte mindestens {0} und maximal {1} Zeichen ein."),
email: "Geben Sie bitte eine gültige E-Mail-Adresse ein.",
url: "Geben Sie bitte eine gültige URL ein.",
date: "Bitte geben Sie ein gültiges Datum ein.",
number: "Geben Sie bitte eine Nummer ein.",
digits: "Geben Sie bitte nur Ziffern ein.",
equalTo: "Bitte denselben Wert wiederholen.",
range: $.validator.format("Geben Sie bitte einen Wert zwischen {0} und {1} ein."),
max: $.validator.format("Geben Sie bitte einen Wert kleiner oder gleich {0} ein."),
min: $.validator.format("Geben Sie bitte einen Wert größer oder gleich {0} ein."),
creditcard: "Geben Sie bitte eine gültige Kreditkarten-Nummer ein."
});
maybe this is usefull for you.
@staabm thanks. i use it also. but it is not used when using remote validation messages or data-msg attributes.
This issue/proposal has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up.
Thank you for contributing :)
Most helpful comment
we use a snippet like the following to translate error messages into DE:
maybe this is usefull for you.