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