How To Translate Cmenu Items

Hi everyone,

After a few months of trying yii im finally getting confortable with it, but im having a very basic problem, or at least I think so…

I know i can use the Yii::t function through my application to translate strings and labels, but for some reason I cant seem to make it work with the CMenu component.

this is what Im trying to do:




public $menu=array(

			array('label' => Yii::t('Option A'), 'url' => array('/optiona')),

		);	



First of all, Is it even possible to pass a translated string to my CMenu item label ?

Everytime I try to do this i get a syntaxis error.

I feel I’m missing something very basic here. Any help would be much appreciated.

Thanks,

Abraham




$this->widget('zii.widgets.CMenu',array(

     'items'=>array(

	 array('label'=>Yii::t('translations','test'), 'url'=>'#')),




It’s working fine for me. I just think you have to give the script name that contain the keywords.

Thanks your your reply, You were right. I was missing the script file with the translated strings.

I was also setting my $items array inside my controller, but i changed it to my view file. Do you know if the Yii:t() function can only be called from a view file?, because if i try to translate my menu items from within my controller i get the syntaxis error. But if I do it from my view everything works as expected.

The reason i try to define my menu items inside the controller is to only declare it once and possibly use it in several views.

Thanks again.

Yes, you can. My controller has a function to send emails to users, and email is fully translated. It works the same way.

See my example:




$mail->Subject = Yii::t('translations','passwordInfo');

$mail->MsgHTML(Yii::t('translations','yourPassIs').': <font color="red">'.$pass);

$mail->AddAddress($email);



Thank you again.

It seems i have an error on my end when I try to translate CMenu items on my controller… but I solved what I was trying to accomplish declaring my items array inside a partial view, so now i can reuse the same menu through many views.

Thanks for your comments :)