L
L
Lomoson2015-04-21 13:30:57
Yii
Lomoson, 2015-04-21 13:30:57

Internationalization in Widget. How to output a message?

I make a widget and if class Search extends WidgetI write I \Yii::t('company', 'Поиск...')get an error:

exception 'yii\base\ErrorException' with message 'syntax error, unexpected '(', expecting ',' or ';''

At least it is not clear why a syntax error is obtained ...
Tell me, please, how to use translations in Widget?
Whole code:
<?php

namespace app\common\components\widget\search;

use \Yii;
use \yii\base\Widget;

class Search extends Widget
{
    public $placeholder = \Yii::t('company', 'Поиск...');

    public function init()
    {

    }

    public function run()
    {

    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-04-21
@Lomoson

Any decent IDE will tell you why what you wrote is invalid.
Perhaps in Yii this should not be done in the constructor, but the general idea is this:

<?php
namespace app\common\components\widget\search;

use \Yii;
use \yii\base\Widget;

class Search extends Widget
{
    public $placeholder;

    public function __construct()
    {
        $this->placeholder = \Yii::t('company', 'Поиск...');
    }

    public function init()
    {

    }

    public function run()
    {

    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question