Translating system messages

Hi there,

I would like to change translation of Yii core messages in my language (PL). Yii Framework is already nicely translated into Polish and all translation is put into yii/messages/pl/yii.php. I would like to change a few lines of it but the best not to touch original file (as it might be mistakely overwritten with next Yii update).

I’ve read proper part of yii documentation (end of chapter 3.) to find out that I should copy a file (if I understand it correctly) yii.php from yii/messages/pl/ to protected/messages/pl/ folder of my webapp and change anything I want inside this copied file.

I did so, edited copy of yii.php in my protected/messages/pl/, changed for example line:


'{attribute} cannot be blank.' => 'Pole {attribute} nie może być puste.',

to:


'{attribute} cannot be blank.' => 'Bla, bla, bla, bla, bla, bla, bla, bla, bla',

saved file and then tried to log in with empty login field to test this translation, only to find out that app still displays orignal text (from original translation file from yii contents) not the one from my protected/messages/pl/ folder.

How to force yii to take translations for system messages from my folder or is there any way to change these system translations without touching files inside core yii folders? When yii takse messages from it’s core folder and when from protected/messages folder? What am I missing or doing wrong?

Auto-answer: Yii does look into webapp’s protected/messages/LanguageID folder, when using Yii:t().

But if one want to translate core (system) messages or zii widgets messages for example, Yii by default is using it’s own core folder. To force it to use yii.php and zii.php translation files from webapp’s folder one must add to configuration file following line:


//For translation of untranslated files or tuning of existing translations

//Force Yii to look in webapp's own 'messages' folder instead of in framework core files

'coreMessages'=>array('basePath'=>'protected/messages'),

That should solve the problem. Developer only needs to create subfolder protected/messages/LanguageID with LanguageID name equal to what is set for language element in config file and put a copy of yii.php and zii.php files there and then translate or tune-up these files.

Solution thanks to this cookbook recipe.

I got some problem when refering this cookbook, the output of the error message is

for info im using ubuntu

I know this is an old post, but for those who may be bumping into this now, the reason for error


Property "CWebApplication.coreMessages" is read only.

is that coreMessages needs to be added as a member of the components array in config as follows:




'components'=>array(

        'coreMessages'=>array('basePath'=>'protected/messages'),

        ...

);