stoimenn
(Sistoimenov)
August 14, 2010, 10:03am
1
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
k0432
(Johocn)
August 14, 2010, 1:07pm
2
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’)));
p3t6
(Peter Tanzer)
September 21, 2011, 2:50pm
4
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);
}