CPhpMessageSource
CPhpMessageSource represents a message source that stores translated messages in PHP scripts.
CPhpMessageSource uses PHP files and arrays to keep message translations.
When
cachingDuration is set as a positive number, message translations will be cached.
Starting from version 1.0.10, messages for an extension class (e.g. a widget, a module) can be specially managed and used.
In particular, if a message belongs to an extension whose class name is Xyz, then the message category
can be specified in the format of 'Xyz.categoryName'. And the corresponding message file
is assumed to be 'BasePath/messages/LanguageID/categoryName.php', where 'BasePath' refers to
the directory that contains the extension class file. When using Yii::t() to translate an extension message,
the category name should be set as 'Xyz.categoryName'.
Property Details
public string $basePath;
the base path for all translated messages. Defaults to null, meaning
the "messages" subdirectory of the application directory (e.g. "protected/messages").
public string $cacheID;
the ID of the cache application component that is used to cache the messages.
Defaults to 'cache' which refers to the primary cache application component.
Set this property to false if you want to disable caching the messages.
public integer $cachingDuration;
the time in seconds that the messages can remain valid in cache.
Defaults to 0, meaning the caching is disabled.
Method Details
|
protected string getMessageFile(string $category, string $language)
|
| $category |
string |
category name |
| $language |
string |
language ID |
| {return} |
string |
the message file path |
Determines the message file name based on the given category and language.
If the category name contains a dot, it will be split into the module class name and the category name.
In this case, the message file will be assumed to be located within the 'messages' subdirectory of
the directory containing the module class file.
Otherwise, the message file is assumed to be under the basePath.
Initializes the application component.
This method overrides the parent implementation by preprocessing
the user request data.
|
protected array loadMessages(string $category, string $language)
|
| $category |
string |
the message category |
| $language |
string |
the target language |
| {return} |
array |
the loaded messages |
Loads the message translation for the specified language and category.