In a comparision with the yii 1,i created a trait in /components/Translate.php
Code in YII 1.0
trait Translate{
public function translate($message, $params = array()){
return Yii::t(Yii::app()->language,$message,$params);
}
}
In components/controller.php i set
use Translate;
So will be ready for use in all application
i can to call
$this->translate('test')
in my controllers and views. Its works
In Yii 2.0
I create my trait
namespace common\components;
trait Translate{
public function translate($message, $params = array()){
return \Yii::t('app',$message,$params);
}
}
In my controller
use common\components\Translate;
...
class SiteController extends Controller
{
use Translate;
public function init()
{
echo $this->translate('testing'); exit;
}
}
The Code above works, but when i try to call
$this->translate('testing')
In my view, displays an error
Calling unknown method: yii\web\View::translate()
Someone to help me? how can i pass translate() directly