Define different message adapter for specific group(s)

Hey there,

I am using CDbMessageSource for messages system-wide, but noticed that Yii does not automatically use CPhpMessageSource for ‘yii’ category messages which apparently are only available as a PHP file.

  • Is there any way to define multiple adapters BY category (for example CPhpMessageSource for ‘yii’ and CDbMessageSource for all others) I know that I can define a 4th parameter in Yii:t() but that’s not really helping as I would have to rewrite thousands of lines of code for that change)?

  • If not, is there an SQL file available which contains the contents of the primary language codes in a compatible format for the default table setup (SourceMessage: id, category, message)?

  • If not, would it be a viable alternative to write an individual, e.g. MiscMessageSource component, which handles this decision (yii > php files, others > database)? Can anyone point me to some docs on how to do that the best way? I’m just started working with Yii yesterday ;)

Thanks in advance for any suggestion! :)

As a dirty hack, use the following code to create correct SQL from one of the correct arrays which contains the yii/zii strings. Modify according to your language


$array = array('your-yii-array-here');


foreach($array as $en => $de)

{

	echo "INSERT INTO SourceMessage(`category`, `message`) VALUES ('yii', '".$en."');\n";

	echo "INSERT INTO Message(`language`, `translation`) VALUES ('de_de', '".$de."');\n";

}

Also note that de_de or en_us won’t work as Yii seems to be using only 2 letter country codes for internal messages. That means, use ‘de’ instead of ‘de_de’ and your messages will all be translated as desired.