PhpMessageSource ​
- Type
- Class
- Namespace
- craft\i18n
- Inherits
- craft\i18n\PhpMessageSource » yii\i18n\PhpMessageSource » yii\i18n\MessageSource » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
Class PhpMessageSource
Public Properties ​
| Property | Description |
|---|---|
| allowOverrides | boolean – Whether the messages can be overridden by translations in the site’s translations folder |
| basePath | string – The base path for all translated messages. |
| behaviors | yii\base\Behavior – List of behaviors attached to this component. |
| fileMap | array – Mapping between message categories and the corresponding message file paths. |
| forceTranslation | boolean – Whether to force message translation when the source and target languages are the same. |
| sourceLanguage | string, null – The language that the original messages are in. |
allowOverrides ​
- Type
- boolean
- Default value
false
Whether the messages can be overridden by translations in the site’s translations folder
Public Methods ​
| Method | Description |
|---|---|
| __call() | Calls the named method which is not a class method. |
| __clone() | This method is called after the object is created by cloning an existing one. |
| __construct() | Constructor. |
| __get() | Returns the value of a component property. |
| __isset() | Checks if a property is set, i.e. defined and not null. |
| __set() | Sets the value of a component property. |
| __unset() | Sets a component property to be null. |
| attachBehavior() | Attaches a behavior to this component. |
| attachBehaviors() | Attaches a list of behaviors to the component. |
| behaviors() | Returns a list of behaviors that this component should behave as. |
| canGetProperty() | Returns a value indicating whether a property can be read. |
| canSetProperty() | Returns a value indicating whether a property can be set. |
| className() | Returns the fully qualified name of this class. |
| detachBehavior() | Detaches a behavior from the component. |
| detachBehaviors() | Detaches all behaviors from the component. |
| ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
| getBehavior() | Returns the named behavior object. |
| getBehaviors() | Returns all behaviors attached to this component. |
| hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
| hasMethod() | Returns a value indicating whether a method is defined. |
| hasProperty() | Returns a value indicating whether a property is defined for this component. |
| init() | Initializes this component. |
| off() | Detaches an existing event handler from this component. |
| on() | Attaches an event handler to an event. |
| translate() | Translates a message to the specified language. |
| trigger() | Triggers an event. |
Protected Methods ​
| Method | Description |
|---|---|
| getMessageFilePath() | Returns message file path for the specified language and category. |
| loadFallbackMessages() | The method is normally called by loadMessages() to load the fallback messages for the language. |
| loadMessages() | Loads the message translation for the specified $language and $category. |
| loadMessagesFromFile() | Loads the message translation for the specified language and category or returns null if file doesn't exist. |
| translateMessage() | Translates the specified message. |
getMessageFilePath() ​
Returns message file path for the specified language and category.
Arguments ​
Returns ​
string – Path to message file
loadMessages() ​
Loads the message translation for the specified $language and $category.
If translation for specific locale code such as en-US isn't found it tries more generic en. When both are present, the en-US messages will be merged over en. See loadFallbackMessages() for details. If the $language is less specific than sourceLanguage, the method will try to load the messages for sourceLanguage. For example: sourceLanguage is en-GB, $language is en. The method will load the messages for en and merge them over en-GB.
Arguments ​
Returns ​
array – The loaded messages. The keys are original messages, and the values are the translated messages.
loadMessagesFromFile() ​
Loads the message translation for the specified language and category or returns null if file doesn't exist.
Arguments ​
$messageFile(string) – Path to message file