At first, I was maked this using $di in the services.php and the next I was used it like this:
$this->translate->_('username'); //return 'Username'
But, I think, this variant is not very comfortable and readable. I have created the translate function in the services.php for use translation in Controllers and Forms:
function translate($resolvedArgs) {
require "../app/languages/en.php";
$translate = new NativeArray(['content' => $l]);
return $translate->_($resolvedArgs);
}
Then I can use it like this:
// ...
class Account__CreateForm extends Form
{
public function initialize()
{
// Username
$username = new Text('username', [
'placeholder' => translate('username')
]);
$username->addValidator(new StringLength([
'messageMinimum' => translate('validation-username'),
'min' => 3
]));
$this->add($username);
}
}
//...
But is this method good? Somehow, it seems to me that this is not the best solution. Is it so? How can I do this right? I hope for your help.