Widget translations
In a similar vein, widgets can also have their own message translation files by following the same process outlined for modules. Using our GreetingWidget
class we created in Chapter 5, Modules, Widgets, and Helpers would look as follows:
<?php
namespace app\components;
use yii\base\Widget;
use yii\helpers\Html;
use Yii;
class GreetingWidget extends Widget
{
public $name = null;
public $greeting;
public function init()
{
parent::init();
Yii::$app->i18n->translations['widgets/GreetingWidget*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@app/components/widgets/GreetingWidget'
];
$hour = date('G');
if ( $hour >= 5 && $hour <= 11 )
$this->greeting = GreetingWidget::t("Good...