Yii Framework Forum: How to use CPhpMessageSource - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

How to use CPhpMessageSource Rate Topic: -----

#1 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 03 February 2009 - 09:54 AM

Hello all,
First off, i like Yii very much and my goal is to learn it and use it in some cool projects,

but, of course, i have more questions then actual knowledge.

Right now i'm stuck at setting language,

how do i use "CPhpMessageSource" ?

In my protected/config/main.php
should i write:

'components'=>array(
...
'messages'=>array(
'class'=>'CPhpMessageSource',
        'basePath'=>realpath(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'messages/ru'),
'language'=>'ru',
),
)


This doesn't work :(
I'm also wondering, what settings are better for best performance? I mean, should i use /framework/messages/ stuff ? or i can use "custom" messages in webroot/protected/messages?
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 February 2009 - 10:00 AM

Are you developing a multilanguage application? If not, you don't need to use this. (If you only want to make those validation messages to appear in Russian, you can simply configure the 'message' option in the rules).

If you ARE developing multilanguage application, you may choose to store translated messages in either PHP array (CPhpMessage) or database (CDbMessageSource). If using the former, you don't need to configure anything since Yii already predefines the 'messages' source. All you need is to put the translated messages under 'protected/messages'.
0

#3 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 03 February 2009 - 10:14 AM

No, it's not a multilanguage application.. yet  ;)

Quote

you can simply configure the 'message' option in the rules

Can you please tell me how to do that? I'm all over docs, but can't find the right way to do it.

I can simply add 'language' => 'ru' to config/main.php but it'll use /framework/messages files, and they are actually can and will change in further Yii releases, and i don't want new Yii version to overwrite my custom messages.
What i mean is I sure can use 'language' option, but it just seems a bit wrong, and i want to know if it's the right way to do - to edit framework files, or is there a nice way to tell Yii to use my customized and translated messages, those i will store in webapp/protected/
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 February 2009 - 10:20 AM

Yes, you also set 'language' property of your application to be 'ru' to make use of the translated messages included in Yii. However, in case a message is not translated in Yii, you still need to do it yourself by explicitly specify the 'message' option. An example is as follows:

class MyModel extends CActiveRecord
{
    public function rules()
    {
        return array(
            array('name', 'required', 'message'=>'This field is required.'),
        );
    }
}

0

#5 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 03 February 2009 - 10:23 AM

so webapp/protected/messages is reserver for only multilanguage applications?
OK, so i think the best to have custom language is to create one in framework dir, framework/messages/ru_c (russioan, custom) ?
Please, correct me if i'm wrong.

Thank you for you replies!
0

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 03 February 2009 - 10:36 AM

Yes, protected/messages is only for multilanguage apps. It's not recommended you change code under framework/.

The best way to do is to set language to be 'ru' and specify 'message' option if a message is not translated or not translated as you expected.
0

#7 User is offline   Spear 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 02-February 09

Posted 05 February 2009 - 04:08 AM

Ok, well, you might actually think that i'm a totall idiot, but i still don't get it.

In template i have:

<?php echo CHtml::label('Remember me next time',CHtml::getActiveId($form,'rememberMe')); ?>


in my model (loginfrom):

public function rules()
{
return array(
// username and password are required
array('username, password', 'required'),

// password needs to be authenticated
array('password', 'authenticate'),
);

}


So, how do i properly change the "Remember me next time" text, without hacking /framework/ stuff? Please, help me.
0

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 05 February 2009 - 07:08 AM

You can directly change the label text in the view.

As an alternative way, you can use the following view code and model code:

view:

<?php echo CHtml::activeLabel($form, 'rememberMe'); ?>


form:

public function attributeLabels()
{
    return array(
          'rememberMe'=>'Remember me next time',
    );
}

0

#9 User is offline   ahmad jahangir 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 24-July 11

Posted 09 August 2011 - 07:36 AM

I have a question :
I use ClistView widget and it has a message "Go to page", that is not accessible in widget to modify it.
how can i change it in much project. and other messages like that.

thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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