I just found that in the symfony2 console command, the default locale defined in config.yml is never used, so the locale is NULL . Therefore, the translator will never use the language version of the translation. This is why the translation key is returned intact instead of the translation.
I got this advice when I run only a console command that tries to translate something, but the directory in the app / cache / dev / translations folder is not generated.
So, this is how I do it to make translations in console commands (in my case, I set its id_ID):
$translator = $this->getContainer()->get('translator'); $translator->setLocale("id_ID"); echo $translator->trans('my.translation.key');
Hope this helps anyone facing the same problem. :)
source share