symfony2: how to use translator in console command
I'm trying to use translator in symfony2 (2.3.0) console command, but I
can't make it work. Here is what I've done so far:
namespace Fast\SisdikBundle\Command;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SendMessageCommand extends ContainerAwareCommand
{
protected function configure() {
$this->setName('mycommand:sendmessage')->setDescription('send
message.');
}
protected function execute(InputInterface $input, OutputInterface
$output) {
$translator = $this->getContainer()->get('translator');
echo $translator->trans('my.translation.key'); // not working
}
}
my.translation.key is exists in messages.yml. Any idea how to make it work?
thanks!
No comments:
Post a Comment