Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • Net
  • None
  • PHP
  • system
    • base
    • caching
      • dependencies
    • collections
    • console
    • db
      • ar
      • schema
        • cubrid
        • mssql
        • mysql
        • oci
        • pgsql
        • sqlite
    • i18n
      • gettext
    • logging
    • test
    • utils
    • validators
    • web
      • actions
      • auth
      • filters
      • form
      • helpers
      • renderers
      • services
      • widgets
        • captcha
        • pagers
  • Text
    • Highlighter
  • zii
    • behaviors
    • widgets
      • grid
      • jui

Classes

  • CChoiceFormat
  • CDateFormatter
  • CDbMessageSource
  • CGettextMessageSource
  • CLocale
  • CMessageSource
  • CMissingTranslationEvent
  • CNumberFormatter
  • CPhpMessageSource
  • Overview
  • Package
  • Class
  • Tree

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',
    );
    
When 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
Extended by CApplicationComponent implements IApplicationComponent
Extended by CMessageSource
Extended by CPhpMessageSource
Package: system\i18n
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
Methods summary
public
# init( )

Initializes the application component. This method overrides the parent implementation by preprocessing the user request data.

Initializes the application component. This method overrides the parent implementation by preprocessing the user request data.

Overrides

CApplicationComponent::init()
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 CPhpMessageSource::$basePath.

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 CPhpMessageSource::$basePath.

Parameters

$category
string
$category category name
$language
string
$language language ID

Returns

string
the message file path
protected array
# loadMessages( string $category, string $language )

Loads the message translation for the specified language and category.

Loads the message translation for the specified language and category.

Parameters

$category
string
$category the message category
$language
string
$language the target language

Returns

array
the loaded messages
Methods inherited from CMessageSource
getLanguage(), onMissingTranslation(), setLanguage(), translate(), translateMessage()
Methods inherited from CApplicationComponent
getIsInitialized()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Constants summary
string CACHE_KEY_PREFIX 'Yii.CPhpMessageSource.'
#
Properties summary
public integer $cachingDuration 0
#

the time in seconds that the messages can remain valid in cache. Defaults to 0, meaning the caching is disabled.

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.

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").

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.

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.

Since

1.1.13
Properties inherited from CMessageSource
$forceTranslation
Properties inherited from CApplicationComponent
$behaviors
Magic properties inherited from CMessageSource
$language
Magic properties inherited from CApplicationComponent
$isInitialized
API documentation generated by ApiGen 2.8.0