Open xcambar opened 7 years ago
@xcambar not sure I follow you here. Where is this partial message being created? Why is it needed? and what are you doing with it after?
Here's what I can achieve with this PR:
validator('date', {
precision: 'day',
message: function(err, input, validator) {
let localizedFormat = moment().localeData().longDateFormat(validator.get('format')); // => DD/MM/YYYY because lang == 'fr_FR'
let translatedFormat = t(localizedFormat); // => JJ/MM/AAAA in french
return validatorsMessages.formatPartialMessage(wrongDateFormat, { format: localizedFormat });
// => {description} must be in the format of JJ/MM/AAAA
},
format: 'L'
})
With the current master of ember-validators, I didn't succeed in having the error message to be This field must be in the format of JJ/MM/AAAA
. If you can provide some guidance towards this with a simple solution, then yes, this PR may be superfluous.
A couple of notes:
{description} must...
instead of directly returning This field must...
This PR allows, with a backward compatible modification, to let the developers partially apply a context to a message.
This is very useful for instance when extending the messages provided by
ember-validations
to reusemessageFor
to do the extension/replacement instead of doing a.replace(...)
manually, which might break eventually...Down to earth example:
wrongDateFormat
("{description} must be in the format of {format}")format
used wasL
(using the moment terminology)L
("MM/DD/YYYY" in en_US and "JJ/MM/AAAA" in fr_FR) in the messageWhat do you think?