Inheritance | yii\i18n\MessageFormatter » yii\base\Component » yii\base\Object |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.0 |
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/i18n/MessageFormatter.php |
MessageFormatter allows formatting messages via ICU message format
This class enhances the message formatter class provided by the PHP intl extension.
The following enhancements are provided:
Offers limited support for message formatting in case PHP intl extension is not installed. However it is highly recommended that you install PHP intl extension if you want to use MessageFormatter features.
The fallback implementation only supports the following message formats:
The fallback implementation does NOT support the 'apostrophe-friendly' syntax. Also messages that are working with the fallback implementation are not necessarily compatible with the PHP intl MessageFormatter so do not rely on the fallback if you are able to install intl extension somehow.
Property | Type | Description | Defined By |
---|---|---|---|
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$errorCode | string | Code of the last error. | yii\i18n\MessageFormatter |
$errorMessage | string | Description of the last error. | yii\i18n\MessageFormatter |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\Component |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\Object |
__get() | Returns the value of a component property. | yii\base\Component |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\Component |
__set() | Sets the value of a component property. | yii\base\Component |
__unset() | Sets a component property to be null. | yii\base\Component |
attachBehavior() | Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\Component |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\Component |
className() | Returns the fully qualified name of this class. | yii\base\Object |
detachBehavior() | Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() | Detaches all behaviors from the component. | yii\base\Component |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
format() | Formats a message via ICU message format | yii\i18n\MessageFormatter |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getErrorCode() | Get the error code from the last operation | yii\i18n\MessageFormatter |
getErrorMessage() | Get the error text from the last operation | yii\i18n\MessageFormatter |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\Component |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component |
init() | Initializes the object. | yii\base\Object |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
parse() | Parses an input string according to an ICU message format pattern. | yii\i18n\MessageFormatter |
trigger() | Triggers an event. | yii\base\Component |
Method | Description | Defined By |
---|---|---|
fallbackFormat() | Fallback implementation for MessageFormatter::formatMessage | yii\i18n\MessageFormatter |
Code of the last error.
public string getErrorCode ( )
Description of the last error.
public string getErrorMessage ( )
Fallback implementation for MessageFormatter::formatMessage
protected false|string fallbackFormat ( $pattern, $args, $locale ) | ||
---|---|---|
$pattern | string |
The pattern string to insert things into. |
$args | array |
The array of values to insert into the format string |
$locale | string |
The locale to use for formatting locale-dependent parts |
return | false|string |
The formatted pattern string or |
Formats a message via ICU message format
It uses the PHP intl extension's MessageFormatter and works around some issues. If PHP intl is not installed a fallback will be used that supports a subset of the ICU message format.
public string|false format ( $pattern, $params, $language ) | ||
---|---|---|
$pattern | string |
The pattern string to insert parameters into. |
$params | array |
The array of name value pairs to insert into the format string. |
$language | string |
The locale to use for formatting locale-dependent parts |
return | string|false |
The formatted pattern string or |
Get the error code from the last operation
public string getErrorCode ( ) | ||
---|---|---|
return | string |
Code of the last error. |
Get the error text from the last operation
public string getErrorMessage ( ) | ||
---|---|---|
return | string |
Description of the last error. |
Parses an input string according to an ICU message format pattern.
It uses the PHP intl extension's MessageFormatter::parse() and adds support for named arguments. Usage of this method requires PHP intl extension to be installed.
public array|boolean parse ( $pattern, $message, $language ) | ||
---|---|---|
$pattern | string |
The pattern to use for parsing the message. |
$message | string |
The message to parse, conforming to the pattern. |
$language | string |
The locale to use for formatting locale-dependent parts |
return | array|boolean |
An array containing items extracted, or |
throws | yii\base\NotSupportedException |
when PHP intl extension is not installed. |
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc-2.0/yii-i18n-messageformatter.html