Почему бы просто не реализовать MvcTranslator
, как для документов ?
class AvailabilityModelFactory implements FactoryInterface
{
public function __invoke( ... )
{
$translator = $container->get('MvcTranslator');
return new AvailabilityModel($translator, ...);
}
}
Использование:
class AvialabilityModel implements InputFilterAwareInterface
{
/**
* @var TranslatorInterface
*/
protected $translator;
public function __construct(
\Zend\I18n\Translator\TranslatorInterface $translator
$new
) {
$this->new = $new;
}
public function getInputFilter()
{
....
$inputFilter->add([
'name' => 'srcTo',
'required' => true,
'validators' => [
[
'name' => Date::class,
C::CFG_OPTIONS=>['format'=>'d-m-Y']
],
[
'name'=> Callback::class,
C::CFG_OPTIONS=>[
'messages'=>[
Callback::INVALID_VALUE =>
$this->translator->translate( // USAGE HERE
'La data deve essere successiva a quella iniziale!'
),
],
'callback'=>function($value,$context=array()){
$d1 = Utils::stringToDate($context['start'],null);
$d2 = Utils::stringToDate($value,null);
return $d2>$d1;
}
]
]
],
'filters'=>[
CommonModel::stringTrim()
]
]);
......
return $this->inputFilter;
}
...
}
(незабудьте инструкции intro для инструкций по настройке)