Yii Framework Forum: can't translate the names in CHtml::listData() with Yii::t() - Yii Framework Forum

Jump to content

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

can't translate the names in CHtml::listData() with Yii::t() Rate Topic: -----

#1 User is offline   Stoimen Stoimenov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-August 10

Posted 14 August 2010 - 05:03 AM

The problem is that I am building a multi language website and in this script:

dropDownList($model, ‘departmentId’, CHtml::listData( Departments::model()->findAll(), ‘id’, ‘name’), array(‘prompt’ => ‘Select a Department’));

The departments are displayed in english (because they are saved like that in the db) but I need to call the names in Yii::t(‘departments’, ‘name’) so that they can be shown in any language. But I can’t achieve that… It looks like the ‘name’ is hard coded in the CHtml::listData()

Is there a way to translate them without breaking the form structure created with the form widget and without creating db tables for every language...

I wonder if you could help me :)
0

#2 User is offline   johocn 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 21-January 10

Posted 14 August 2010 - 08:07 AM

View PostStoimen Stoimenov, on 14 August 2010 - 05:03 AM, said:

The problem is that I am building a multi language website and in this script:

dropDownList($model, ‘departmentId’, CHtml::listData( Departments::model()->findAll(), ‘id’, ‘name’), array(‘prompt’ => ‘Select a Department’));

The departments are displayed in english (because they are saved like that in the db) but I need to call the names in Yii::t(‘departments’, ‘name’) so that they can be shown in any language. But I can’t achieve that… It looks like the ‘name’ is hard coded in the CHtml::listData()

Is there a way to translate them without breaking the form structure created with form widget and without creating db tables for every language...

I wonder if you could help me :)

dropDownList($model, ‘departmentId’, CHtml::listData( Departments::model()->findAll(), ‘id’, ‘name’), array(‘prompt’ => Yii::t(‘file name’, 'Select a Department’)));
0

#3 User is offline   Stoimen Stoimenov 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 14-August 10

Posted 14 August 2010 - 12:33 PM

I fixed it...
0

#4 User is offline   p3t6 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 25-August 11

Posted 21 September 2011 - 09:50 AM

View PostStoimen Stoimenov, on 14 August 2010 - 12:33 PM, said:

I fixed it...

Hi could you tell me how you fixed the problem?
thanks in advance
Peter
0

#5 User is offline   Dick Brouwers 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-June 11

Posted 12 January 2012 - 08:29 AM

View Postp3t6, on 21 September 2011 - 09:50 AM, said:

Hi could you tell me how you fixed the problem?
thanks in advance
Peter


I had the same problem and fixed it like this:


$listData = CHtml::listData(Model::model()->findAll(),'id','name');
$t_listData = array();
foreach($listData as $key => $item)
{
	$t_listData[$key]=Yii::t('translation',$item);
}

0

#6 User is offline   DryKillLogic 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 14-December 10

Posted 24 July 2012 - 03:28 PM

Try this http://www.yiiframew...in-just-1-line/

See ya!
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