User locale in command

translation
i18n

#1

I have created a command that generates some reports periodically and sends them to users. I want to send the mails, from the command, in the user locale (is a user column in DB). How can I set the user locale in a command, to make __("My string") be translated?


#2

OK… sorry. right simple, even in commands (I thought it would be a special case):

<?php
namespace App\Command;

use Cake\Console\Arguments;
use Cake\Console\Command;
use Cake\Console\ConsoleIo;
use Cake\I18n\I18n;


class HelloCommand extends Command
{

    public function execute(Arguments $args, ConsoleIo $io)
    {

        I18n::setLocale('es_ES');
        echo __("Actions") . "\n";

    }

}

Output:

$ bin/cake hello
Acciones