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?
Thanks!
Chiliec
(Swordyx)
January 8, 2015, 10:58am
2
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:
"companyAddress"
instead of the actual address that is specified inside the translation array.
Any ideas?
Chiliec
(Swordyx)
January 8, 2015, 1:33pm
4
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):
require_once('path/to/message/ru/message.php')