Class yii\i18n\I18N
Inheritance | yii\i18n\I18N » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable |
Available since version | 2.0 |
I18N provides features related with internationalization (I18N) and localization (L10N).
I18N is configured as an application component in yii\base\Application by default.
You can access that instance via Yii::$app->i18n
.
Public Properties
隐藏继承的属性 Hide inherited properties
属性Property | 类型 Type | 简介 Description | 定义在 Defined By |
---|---|---|---|
$behaviors | yii\base\Behavior[] | List of behaviors attached to this component | yii\base\Component |
$messageFormatter | yii\i18n\MessageFormatter | The message formatter to be used to format message via ICU message format. | yii\i18n\I18N |
$translations | array | List of yii\i18n\MessageSource configurations or objects. | yii\i18n\I18N |
Public Methods
隐藏继承的方法 Hide inherited methods
方法 Method | 简介 Description | 定义在 Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() | This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() | Constructor. | yii\base\BaseObject |
__get() | Returns the value of an object property. | yii\base\BaseObject |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() | Sets value of an object property. | yii\base\BaseObject |
__unset() | Sets an object property to null. | yii\base\BaseObject |
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\BaseObject |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() | Returns the fully qualified name of this class. | yii\base\BaseObject |
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 using yii\i18n\MessageFormatter. | yii\i18n\I18N |
getBehavior() | Returns the named behavior object. | yii\base\Component |
getBehaviors() | Returns all behaviors attached to this component. | yii\base\Component |
getMessageFormatter() | Returns the message formatter instance. | yii\i18n\I18N |
getMessageSource() | Returns the message source for the given category. | yii\i18n\I18N |
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\BaseObject |
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() | Initializes the component by configuring the default message categories. | yii\i18n\I18N |
off() | Detaches an existing event handler from this component. | yii\base\Component |
on() | Attaches an event handler to an event. | yii\base\Component |
setMessageFormatter() | yii\i18n\I18N | |
translate() | Translates a message to the specified language. | yii\i18n\I18N |
trigger() | Triggers an event. | yii\base\Component |
属性详情 Property Details
The message formatter to be used to format message via ICU message format.
List of yii\i18n\MessageSource configurations or objects. The array keys are message category patterns, and the array values are the corresponding yii\i18n\MessageSource objects or the configurations for creating the yii\i18n\MessageSource objects.
The message category patterns can contain the wildcard *
at the end to match multiple categories with the same prefix.
For example, app/*
matches both app/cat1
and app/cat2
.
The *
category pattern will match all categories that do not match any other category patterns.
This property may be modified on the fly by extensions who want to have their own message sources registered under their own namespaces.
The category yii
and app
are always defined. The former refers to the messages used in the Yii core
framework code, while the latter refers to the default message category for custom application code.
By default, both of these categories use yii\i18n\PhpMessageSource and the corresponding message files are
stored under @yii/messages
and @app/messages
, respectively.
You may override the configuration of both categories.
方法详情 Method Details
Formats a message using yii\i18n\MessageFormatter.
public string format ( $message, $params, $language ) | ||
$message | string | The message to be formatted. |
$params | array | The parameters that will be used to replace the corresponding placeholders in the message. |
$language | string | The language code (e.g. |
return | string | The formatted message. |
---|
Returns the message formatter instance.
public yii\i18n\MessageFormatter getMessageFormatter ( ) | ||
return | yii\i18n\MessageFormatter | The message formatter to be used to format message via ICU message format. |
---|
Returns the message source for the given category.
public yii\i18n\MessageSource getMessageSource ( $category ) | ||
$category | string | The category name. |
return | yii\i18n\MessageSource | The message source for the given category. |
---|---|---|
throws | yii\base\InvalidConfigException | if there is no message source available for the specified category. |
Initializes the component by configuring the default message categories.
public void init ( ) |
public void setMessageFormatter ( $value ) | ||
$value | string|array|yii\i18n\MessageFormatter | The message formatter to be used to format message via ICU message format. Can be given as array or string configuration that will be given to Yii::createObject() to create an instance or a yii\i18n\MessageFormatter instance. |
Translates a message to the specified language.
After translation the message will be formatted using yii\i18n\MessageFormatter if it contains
ICU message format and $params
are not empty.
public string translate ( $category, $message, $params, $language ) | ||
$category | string | The message category. |
$message | string | The message to be translated. |
$params | array | The parameters that will be used to replace the corresponding placeholders in the message. |
$language | string | The language code (e.g. |
return | string | The translated and formatted message. |
---|