Difference between #4 and #5 of
How to customize Yii core messages?

Revision #5 has been created by rAWTAZ on Aug 26, 2011, 12:19:00 PM with the memo:

Updated with elaborate instructions to make this work even when the protected folder is not in the webroot.
« previous (#4) next (#6) »

Changes

Title unchanged

How to customize Yii core messages?

Category unchanged

Tutorials

Yii version unchanged

Tags changed

core messages, translation, i18n

Content changed

[...]
return array(
......
'language'=>'de',
'components'=>array(
'coreMessages'=>array(
'basePath'=>
'protected/messages'null,
),
......
[...]
```

In the above, we specify that the application is targeted to German users and
that the translated messages are located under the directory `protected/messages`to be loaded from under the default `basePath` of the `coreMessages` component, which by default is the directory represented by the path alias `application.messages`. The latter effectively translates to the `protected/messages` folder, regardless of where `protected` is located in the filesystem. Please refer to the Yii Guide for more [information about path aliases](doc/guide/basics.namespace).
 
 
It might seem odd that we set the `basePath` to null instead of `protected/messages`. The reason we do that is to support the case where the `protected` folder has been moved out of the webroot, because the relative path `protected/messages` will then not be found starting from the webroot. The webroot is where the Yii application is located in the filesystem during runtime.
 
 
If we want to specify another basePath for the messages than this default one, we have to provide either an absolute path to the folder (such as `/var/www/messages`), or a path that during runtime will be relative the webroot (for example `../protected/messages` if the `protected` directory is a located in the same directory as the webroot, i.e. moved one step up from the default location)
.

Next, we need to provide our translations. Under the directory `protected/messages`, create a subdirectory named `de` which corresponds to the target language we set in the application configuration. And under the `de` directory, create a new file named `yii.php`. To this end, we should have the following directory structure:

~~~
WebRoot/
[...]
17 0
16 followers
Viewed: 67 800 times
Version: 1.1
Category: Tutorials
Written by: qiang
Last updated by: Yang He
Created on: Feb 25, 2009
Last updated: 11 years ago
Update Article

Revisions

View all history