Class CPhpMessageSource
CPhpMessageSource represents a message source that stores translated messages in PHP scripts.
CPhpMessageSource uses PHP files and arrays to keep message translations.- All translations are saved under the
CPhpMessageSource::$basePath
directory. - Translations in one language are kept as PHP files under an individual subdirectory whose name is the same as the language ID. Each PHP file contains messages belonging to the same category, and the file name is the same as the category name.
- Within a PHP file, an array of (source, translation) pairs is returned. For
example:
return array( 'original message 1' => 'translated message 1', 'original message 2' => 'translated message 2', );
CPhpMessageSource::$cachingDuration
is set as a positive number, message translations
will be cached.
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'.
- CComponent
- CApplicationComponent implements IApplicationComponent
- CMessageSource
- CPhpMessageSource
Copyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/i18n/CPhpMessageSource.php
public
|
|
protected
string
|
#
getMessageFile( string $category, string $language )
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 |
protected
array
|
#
loadMessages( string $category, string $language )
Loads the message translation for the specified language and category. |
getLanguage(),
onMissingTranslation(),
setLanguage(),
translate(),
translateMessage()
|
getIsInitialized()
|
string |
CACHE_KEY_PREFIX
|
'Yii.CPhpMessageSource.' |
public
integer
|
$cachingDuration | 0 |
#
the time in seconds that the messages can remain valid in cache. Defaults to 0, meaning the caching is disabled. |
public
string
|
$cacheID | 'cache' |
#
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
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
array
|
$extensionPaths | array() |
#
the message paths for extensions that do not have a base class to use as category prefix. The format of the array should be: array( 'ExtensionName' => 'ext.ExtensionName.messages', ) Where the key is the name of the extension and the value is the alias to the path of the "messages" subdirectory of the extension. When using Yii::t() to translate an extension message, the category name should be set as 'ExtensionName.categoryName'. Defaults to an empty array, meaning no extensions registered. |
$forceTranslation
|
$behaviors
|
$language
|
$isInitialized
|