Yii Framework Forum: Translating system messages - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Translating system messages (or overriding existing translations) Rate Topic: -----

#1 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,257
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 25 October 2010 - 04:43 AM

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?
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#2 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,257
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 26 October 2010 - 04:38 AM

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.
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!
0

#3 User is offline   alifdalya 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 17-October 12

Posted 06 December 2012 - 02:40 AM

View PostTrejder, on 26 October 2010 - 04:38 AM, said:

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

Quote

Property "CWebApplication.coreMessages" is read only.
for info im using ubuntu
0

#4 User is offline   benomatis 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 27-November 13

Posted 11 May 2018 - 03:30 PM

View Postalifdalya, on 06 December 2012 - 02:40 AM, said:

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'),
        ...
);

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users