Yii Framework Forum: GridView, translation of records - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

GridView, translation of records

#1 User is offline   xPeng 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 04-August 15

Posted 08 November 2017 - 07:27 AM

I'v found the solution:
http://www.yiiframew...post__p__313655

<?= GridView::widget([
        'dataProvider' => $dataProvider,
         ...   
            
            [
                'attribute' => yii::t('app', 'fruit')
            ],
            
         ...


Doesn't work:
yii::t('app', 'fruit')


Thanks in advance.
0

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,362
  • Joined: 16-February 11
  • Location:Japan

Posted 08 November 2017 - 07:47 AM

<?= GridView::widget([
        'dataProvider' => $dataProvider,
         ...   
            
            [
                'attribute' => 'payment_company',
                'label' => yii::t('app', 'payment_company')
            ],
            
         ...


Or, I would rather recommend you using "yii::t('app', 'payment_company')" in attributeLabels() method in your model class.
0

#3 User is offline   xPeng 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 04-August 15

Posted 08 November 2017 - 10:13 AM

View Postsoftark, on 08 November 2017 - 07:47 AM, said:

<?= GridView::widget([
        'dataProvider' => $dataProvider,
         ...   
            
            [
                'attribute' => 'payment_company',
                'label' => yii::t('app', 'payment_company')
            ],
            
         ...


Or, I would rather recommend you using "yii::t('app', 'payment_company')" in attributeLabels() method in your model class.

Thanks, but I didn't mean the lable. The payment_company was bad example. So I changed the Gridview with 'fruit'.

the records of the fruit are:
Apple
pear

I want to tranlate it into German in the column "fruit":
Apfel
Birne
0

#4 User is offline   xPeng 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 04-August 15

Posted 08 November 2017 - 11:22 AM

I have tryed:
 
1.
['attribute' => yii::t('app', '{fruit}', ['fruit' => 'fruit'])],

2.
yii::t('app', '{fruit}', ['fruit' => 'fruit'])

3.
yii::t('app', 'fruit')

But they are all show the same:
Apple
pear

not:
Apfel
Birne
0

#5 User is offline   jkofsky 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 683
  • Joined: 17-May 10
  • Location:Pensacola, Florida

Posted 08 November 2017 - 01:39 PM

View PostxPeng, on 08 November 2017 - 11:22 AM, said:

I have tryed:
 
1.
['attribute' => yii::t('app', '{fruit}', ['fruit' => 'fruit'])],

2.
yii::t('app', '{fruit}', ['fruit' => 'fruit'])

3.
yii::t('app', 'fruit')

But they are all show the same:
Apple
pear

not:
Apfel
Birne

I'm not sure you can do what you are trying to do. The Yii::t() looks at a file, 'app' in your case, looks for 'fruit', and pulls what it has as the translation. You would need to have a translation in there FOR EVERY FRUIT possible.

Data in a table is normally displayed AS IS. You need to look at another mechanism, Lookup table or extra column, to support the translations of the data keeping in mind EVERY language you want to support.
Do, or do not. There is no 'try.' Jedi Master Yoda
0

#6 User is offline   xPeng 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 04-August 15

Posted 09 November 2017 - 02:05 AM

So here the solution(table: Billing; attribute: payment_company).

to translate of all records of 'payment_company':
1. call the getModels(), method of ActiveDataProvider.
2. use foreach translate the records.

That's all!


Example, in controller:
            $dataProvider = new ActiveDataProvider([
                'query' => Billing::find()
            ]);
            
            $dataProviderModels = $dataProvider->getModels();
            
            foreach($dataProviderModels as $key=>$item){
                $dataProviderModels[$key]['payment_company'] = yii::t('app', $dataProviderModels[$key]['payment_company']);
            }

             return $this->render('index', [
                'dataProvider' => $dataProvider,
             ]);




End
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users