I created a custom component, MessageSource to retrieve both the specified local translations and the default master translations. I then merge these 2 arrays together in a way that the local values will override the default values on those same keys. The component is extended from CPhpMessageSource. Thereafter i overload the loadMessages functionality. The getMessages is actually the same as the CPhpMessageSource’s loadMessages.
protected/components/MessageSource.php:
<?php
class MessageSource extends CPhpMessageSource
{
/**
* Loads the message translation for the specified language and category.
* @param string $category the message category
* @param string $language the target language
* @return array the loaded messages
*/
protected function getMessages($category,$language)
{
$messageFile=$this->getMessageFile($category,$language);
if($this->cachingDuration>0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null)
{
$key=self::CACHE_KEY_PREFIX . $messageFile;
if(($data=$cache->get($key))!==false)
return unserialize($data);
}
if(is_file($messageFile))
{
$messages=include($messageFile);
if(!is_array($messages))
$messages=array();
if(isset($cache))
{
$dependency=new CFileCacheDependency($messageFile);
$cache->set($key,serialize($messages),$this->cachingDuration,$dependency);
}
return $messages;
}
else
return array();
}
/**
* Loads the message translation for the specified language and category and merged it with the default.
* @param string $category the message category
* @param string $language the target language
* @return array the merged messages array
*/
protected function loadMessages($category,$language)
{
// Loads the message translation for the specified language and category.
$localizedMessages = $this->getMessages($category,$language);
// Loads the message translation for the default language and category.
$defaultMessages = $this->getMessages($category, Yii::app()->sourceLanguage);
return CMap::mergeArray($defaultMessages,$localizedMessages);
}
}