Versions
Look up a class, method, property or event

CMessageSource

Package system.i18n
Inheritance abstract class CMessageSource » CApplicationComponent » CComponent
Implements IApplicationComponent
Subclasses CDbMessageSource, CGettextMessageSource, CPhpMessageSource
Since 1.0
Version $Id: CMessageSource.php 1365 2009-08-28 16:12:02Z qiang.xue $
CMessageSource is the base class for message translation repository classes.

A message source is an application component that provides message internationalization (i18n). It stores messages translated in different languages and provides these translated versions when requested.

A concrete class must implement loadMessages or override translateMessage.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
behaviors array the behaviors that should be attached to this component. CApplicationComponent
isInitialized boolean whether this application component has been initialized (i. CApplicationComponent
language string the language that the source messages are written in. CMessageSource

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. CComponent
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getIsInitialized() CApplicationComponent
getLanguage() CMessageSource
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
init() Initializes the application component. CApplicationComponent
onMissingTranslation() Raised when a message cannot be translated. CMessageSource
raiseEvent() Raises an event. CComponent
setLanguage() CMessageSource
translate() Translates a message to the specified language. CMessageSource

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
loadMessages() Loads the message translation for the specified language and category. CMessageSource
translateMessage() Translates the specified message. CMessageSource

Events

Hide inherited events

EventDescriptionDefined By
onMissingTranslation Raised when a message cannot be translated. CMessageSource

Property Details

language property
public string getLanguage()
public void setLanguage(string $language)

the language that the source messages are written in. Defaults to application language.

Method Details

getLanguage() method
public string getLanguage()
{return} string the language that the source messages are written in. Defaults to application language.

loadMessages() method
abstract 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.

onMissingTranslation() method
public void onMissingTranslation(CMissingTranslationEvent $event)
$event CMissingTranslationEvent the event parameter

Raised when a message cannot be translated. Handlers may log this message or do some default handling. The CMissingTranslationEvent::message property will be returned by translateMessage.

setLanguage() method
public void setLanguage(string $language)
$language string the language that the source messages are written in.

translate() method
public string translate(string $category, string $message, string $language=NULL)
$category string the message category
$message string the message to be translated
$language string the target language. If null (default), the application language will be used. This parameter has been available since version 1.0.3.
{return} string the translated message (or the original message if translation is not needed)

Translates a message to the specified language.

Note, if the specified language is the same as the source message language, messages will NOT be translated.

If the message is not found in the translations, an onMissingTranslation event will be raised. Handlers can mark this message or do some default handling. The CMissingTranslationEvent::message property of the event parameter will be returned.

translateMessage() method
protected string translateMessage(string $category, string $message, string $language)
$category string the category that the message belongs to
$message string the message to be translated
$language string the target language
{return} string the translated message

Translates the specified message. If the message is not found, an onMissingTranslation event will be raised.

Be the first person to leave a comment

Please to leave your comment.