Dear Raoul
I hope you remember me, Since I have given a PM to you when you initially made this post.
That time I just downloaded some user management modules(or extensions) and istalled them.
Some of them have intrinsic message translation files for very few languages.
What all I needed was just to add one line in CWebModule::init method.
Yii::app()->language='de';
After that tranlation messages all over the application in German.
I felt that since these extensions strictly adhered to the modular architecture of YII,once language setting
changed they started to look into the message files available inside the module itself.
What can we do when modules or extensions failed in localizing the message files?.
How we can we force the a module to look into a particular messages folder that may reside in the other module?.
Let us have a module with an id sunlight.
Now when this module is instantiated, we are going to change the language to fr.
modules/sunlight/SunlightModule.php
class SunlightModule extends CWebModule
{
public function init()
{
$this->setImport(array(
'sunlight.models.*',
'sunlight.components.*',
));
Yii::app()->language="fr";//SETTING THE LANGUAGE
}
.............................
Now we can create the folder messages in sunlight folder.
Inside the sunlight folder we can create the folder fr.
Let me have translation file inside the fr.
modules/sunlight/messages/fr/greeting.php
?php
return array(
'hello!, good morning!'=>'bonjour!',
'hello!, good evening!'=>'bonsoir!',
'have a good day!'=>'bonne journée!',
'have a good evening!'=>'bonne soirée!',
'good luck!'=>'bon courage!'
);
?>
Now we can instruct YII to look at these files.
We have to declare messages component inside the main.php.
'components'=>array(
'messages'=>array(
'class'=>'CPhpMessageSource',
'extensionPaths'=>array(
'sunlight'=>'application.modules.sunlight.messages',
),
),
...........................................
By setting the extensionPaths property, we can literally map the message files situated in various extensions or
modules.
Have a look at the API.
CPhpMessageSource::extensionPaths
Now we can translate a message into french in a view inside the Module.
echo Yii::t('sunlight.greeting','have a good evening!'); //ouputs bonne soirée!
Note that the first parameter should be in the format of classId.catagoryName.
The same things can be easily achieved withoUt declaring messages component.
For that we can add one more line to CWebModule::init method.
public function init()
{
$this->setImport(array(
'sunlight.models.*',
'sunlight.components.*',
));
Yii::app()->language="fr";
Yii::app()->messages->basePath=Yii::getPathOfAlias('application.modules.sunlight.messages');
//You can have your messages files wherever you want.
//We can instruct YII to look into those files.
}
Now we can translate a message into french in a view inside the Module.
echo Yii::t('greeting','have a good evening!'); //ouputs bonne soirée!. no need to call sunlight.greeting
I hope I helped a bit.
Regards.