Hitman
(Kirill2)
August 25, 2009, 6:59am
1
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
pestaa
(Pestaa)
August 25, 2009, 7:01am
2
I believe CPhpMessageSource::basePath the solution you’re looking for.
Hitman
(Kirill2)
August 25, 2009, 7:07am
3
Yes, but CPhpMessageSource::basePath how to register it in each module?
pestaa
(Pestaa)
August 25, 2009, 7:45am
4
I’d extend it and determine the basePath in the constructor, so you don’t have to worry even if you create other instances.
Hitman
(Kirill2)
August 25, 2009, 7:54am
5
You talk about the class constructor CPhpMessageSource? I do not quite understand, but where I later override basePath?
pestaa
(Pestaa)
August 25, 2009, 8:49am
6
Yes, you may create MyPhpMessageSource which extends the original class, and override the constructor.
public function __construct()
{
parent::__construct();
$this->basePath = ...
}
Hitman
(Kirill2)
August 25, 2009, 9:56am
7
but how do I call this class in the module? Because the standard is invoked as Yii:: t ();
pestaa
(Pestaa)
August 25, 2009, 11:41am
8
Yii::t() uses message component, so you can override that via configuration array:
'components'=>array(
...
'message'=>array(
'class'=>'path.to.MyPhpMessageSource',
)
...
)
Hitman
(Kirill2)
August 25, 2009, 12:11pm
9
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',
);
pestaa
(Pestaa)
August 25, 2009, 8:41pm
11
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.
Hitman
(Kirill2)
August 25, 2009, 8:49pm
12
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?
Hitman
(Kirill2)
August 26, 2009, 6:58am
13
Can I somehow specify the path to the new class? After all, he will be constantly changing depending on the module.
Hitman
(Kirill2)
August 26, 2009, 9:42pm
14
Excuse me for perseverance, really want to know, as a rule do? Thanks in advance!
qiang
(Qiang Xue)
August 27, 2009, 7:54pm
15
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.