Yii Framework Forum: How To Translate Cmenu Items - Yii Framework Forum

Jump to content

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

How To Translate Cmenu Items Rate Topic: -----

#1 User is offline   avraham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-November 12

Posted 01 April 2013 - 03:17 PM

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
0

#2 User is offline   Dih 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 07-January 13

Posted 01 April 2013 - 03:50 PM

$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.
0

#3 User is offline   avraham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-November 12

Posted 01 April 2013 - 04:49 PM

View PostDih, on 01 April 2013 - 03:50 PM, said:

$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.
0

#4 User is offline   Dih 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 07-January 13

Posted 02 April 2013 - 06:31 AM

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);

0

#5 User is offline   avraham 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 08-November 12

Posted 02 April 2013 - 10:50 AM

View PostDih, on 02 April 2013 - 06:31 AM, said:

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 :)
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