Calling Yii::t() from CConsoleCommand

Seems I am unable to use Yii’s translate function from a Yii console application.

When I run ./yiic doSomethingCommand, the Yii::t() function that is called inside that code doesn’t work and does not lookup the correct translation from the language file/array I created.

Any idea how to resolve this?


Try to add string (for example - russian language):

'language' => 'ru'

in config/console.php.

Thanks, but it doesn’t make any difference. The code is still outputting the array index value passed into Yii::t.

i.e. When I execute the following code with Yii console command:

<?php echo Yii::t('message', 'companyAddress');?>

It is outputting:


instead of the actual address that is specified inside the translation array.

Any ideas?

Try to specify the messages component in your console.php configuration:

'messages' => array(

  'class' => 'CPhpMessageSource',

  'basePath' => 'path/to/message/ru/message.php',


or hardcode include at first (bad smells):