# Class yii\i18n\I18N

Inheritance | yii\i18n\I18N » yii\base\Component » yii\base\BaseObject
Implements | yii\base\Configurable
Available since version | 2.0
Source Code | https://github.com/yiisoft/yii2/blob/master/framework/i18n/I18N.php

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. This property is read-only. | yii\base\Component
$messageFormatter | yii\i18n\MessageFormatter | The message formatter to be used to format message via ICU message format. Note that the type of this property differs in getter and setter. See getMessageFormatter() and setMessageFormatter() for details. | 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\Component
__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 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\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\Component
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\base\Component
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

$messageFormatter public property

The message formatter to be used to format message via ICU message format. Note that the type of this property differs in getter and setter. See getMessageFormatter() and setMessageFormatter() for details.

public yii\i18n\MessageFormatter $messageFormatter = null
$translations public property

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.

public array $translations = null

## Method Details

format() public method

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. `en-US`, `en`).
return | string | The formatted message.

getMessageFormatter() public method

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.

getMessageSource() public method

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.

init() public method

Initializes the component by configuring the default message categories.

public void init ( )

setMessageFormatter() public method

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.

translate() public method

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. `en-US`, `en`).
return | string | The translated and formatted message.