Open bkilinc opened 5 years ago
@bkilinc can you maybe outline a test case for what you'd like the behavior to be?
I want to use something like this as a translator object. This is not possible, because AbstractValidator does not pass messageKey to translator object.
class myTranslator implements \Zend\Validator\Translator\TranslatorInterface
{
protected $translations = [
'dateInvalid' => "Invalid type given. String, integer, array or DateTime expected",
'dateInvalidDate'=> "The input does not appear to be a valid date",
'dateFalseFormat' => "The input does not fit the date format '%format%'",
];
public function translate($messageKey, $textDomain = 'default', $locale = null)
{
return $this->translations[$messageKey];
}
}
@bkilinc
AbstractValidator
uses the text of the message, because if no translation exists than the message itself is used as fallback by the translator.dateInvalid
or dateFalseFormat
in his translation files which can then lead to incorrect translations.Thanks, I was creating my custom validator. I would like to use messageKey for looking up translations, because default message may also change. when I saw "protected function translateMessage($messageKey, $message)" in "AbstractValidator", I thought I could do this. But now I understand that, it is not possible with current implementation.
This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at https://github.com/laminas/laminas-validator/issues/1.
I would like to translate validation messages using
messageKeys
as message strings may change. ButtranslateMessage
inAbstractValidator
does not use$messageKey
parameter for translating, even if it is defined as method parameter. It uses message string to translate.