CPhpMessageSource and modules

Good day! Encounter this problem in a modular annex would use CPhpMessageSource for each module with an individual folder messages.

Ie Now the structure looks like this:


protected

-modules

- pages

- users

messages

-ru_ru

-en_us

I would like to do:


protected

-modules

- pages

--- messages

---- ru_ru

---- en_us

- users

I believe CPhpMessageSource::basePath the solution you’re looking for.

Yes, but CPhpMessageSource::basePath how to register it in each module?

I’d extend it and determine the basePath in the constructor, so you don’t have to worry even if you create other instances.

You talk about the class constructor CPhpMessageSource? I do not quite understand, but where I later override basePath?

Yes, you may create MyPhpMessageSource which extends the original class, and override the constructor.




public function __construct()

{

   parent::__construct();

   $this->basePath = ...

}



but how do I call this class in the module? Because the standard is invoked as Yii:: t ();

Yii::t() uses message component, so you can override that via configuration array:




'components'=>array(

   ...

   'message'=>array(

      'class'=>'path.to.MyPhpMessageSource',

   )

   ...

)



I did so, but did not achieve the desired effect.

In StlMessageSource




<?php


class StlPhpMessageSource extends CPhpMessageSource

{


	public function __construct()

	{

   		parent::__construct();

   		$this->basePath = '';

	}


}



In config:




<?


return array(

	'sourceLanguage'=>'ru_ru',

    'language'=>'en_us',

	'components'=>array(

   		'message'=>

   		array(

      		'class'=>'./protected/components/StlMessageSource.php',

      		'basePath' => './protected/modules/index/messages'

   		),

	),

);



In module view:




<?=Yii::t('admin', 'Настройки сайта'); ?>

<?=Yii::t('admin', 'Информация о системе'); ?>



In modules/index/messages:




<?php


return array(

		'Настройки сайта' => 'Site settings',

		'CSS шаблон' => 'CSS template',

		'Информация о системе' => 'Information about system',

		'Параметр' => 'Param',

		'Значение' => 'Value',

		'Размер БД' => 'Size of database',

		'Место на диске' => 'Place of hard disk',

		'Версия PHP' => 'PHP version',

		'Версия Yii Framework' => 'Yii Framework version',

		'Версия Stlanik CMS' => 'Stlanik CMS version',

		'Текущий адрес сайта' => 'Current site URL',

	);



Help me please :)

Why did you emptied basePath in the constructor? I thought you wanted it to be module-dependent.

If you know what the exact path will be, you don’t need to extend the original class.

Ways will be different for each module of his own, so I decided to make it there empty, and in the config file to specify the path for each module of his own. And how I was supposed to do?

Can I somehow specify the path to the new class? After all, he will be constantly changing depending on the module.

Excuse me for perseverance, really want to know, as a rule do? Thanks in advance!

In your module’s init() method, you can do the following:




Yii::app()->configure(array(

   'components'=>array(

       'myModuleMessages'=>array(

           'class'=>'CPhpMessageSource',

           'basePath'=>$this->basePath.'/messages',

       ),

   ),

));



When you call Yii::t(), make sure you specify the $source parameter.

Thanx a lot!