Craft 3 Class Reference

Class craft\i18n\I18N

Inheritance
craft\i18n\I18N » yii\i18n\I18N » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Available since version
3.0
Source Code
https://github.com/craftcms/cms/blob/master/src/i18n/I18N.php

Public Properties
Property Type Description Defined By
$translations array List of yii\i18n\MessageSource configurations or objects. yii\i18n\I18N
Public 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
getAllLocaleIds() Returns an array of all known locale IDs. craft\i18n\I18N
getAllLocales() Returns an array of all known locales. craft\i18n\I18N
getAppLocaleIds() Returns an array of the locale IDs which Craft has been translated into. The list of locales is based on whatever files exist in vendor/craftcms/cms/src/translations/. craft\i18n\I18N
getAppLocales() Returns an array of locales that Craft is translated into. The list of locales is based on whatever files exist in vendor/craftcms/cms/src/translations/. craft\i18n\I18N
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getEditableLocaleIds() Returns an array of the editable locale IDs. craft\i18n\I18N
getEditableLocales() Returns a list of locales that are editable by the current user. craft\i18n\I18N
getIsIntlLoaded() Returns whether the Intl extension is loaded. craft\i18n\I18N
getLocaleById() Returns a locale by its ID. craft\i18n\I18N
getMessageFormatter() Returns the message formatter instance. yii\i18n\I18N
getMessageSource() Returns the message source for the given category. yii\i18n\I18N
getPrimarySiteLocale() Returns the site's primary locale. The primary locale is whatever is listed first in Settings > Locales in the control panel. craft\i18n\I18N
getPrimarySiteLocaleId() Returns the site's primary locale ID. The primary locale is whatever is listed first in Settings > Locales in the control panel. craft\i18n\I18N
getSiteLocaleIds() Returns an array of the site locale IDs. craft\i18n\I18N
getSiteLocales() Returns an array of the site locales. craft\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. craft\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. craft\i18n\I18N
trigger() Triggers an event. yii\base\Component

Method Details

getAllLocaleIds() public method #

Returns an array of all known locale IDs.

If the PHP intl extension is loaded, then this will be based on all of the locale IDs it knows about. Otherwise, it will be based on the locale data files located in vendor/craftcms/cms/src/config/locales/ and config/locales/.

public array getAllLocaleIds ( )
return array An array of locale IDs.

getAllLocales() public method #

Returns an array of all known locales.

See also getAllLocaleIds().

public craft\i18n\Locale[] getAllLocales ( )
return craft\i18n\Locale[] An array of craft\i18n\Locale objects.

getAppLocaleIds() public method #

Returns an array of the locale IDs which Craft has been translated into. The list of locales is based on whatever files exist in vendor/craftcms/cms/src/translations/.

public array getAppLocaleIds ( )
return array An array of locale IDs.

getAppLocales() public method #

Returns an array of locales that Craft is translated into. The list of locales is based on whatever files exist in vendor/craftcms/cms/src/translations/.

public craft\i18n\Locale[] getAppLocales ( )
return craft\i18n\Locale[] An array of craft\i18n\Locale objects.
throws yii\base\Exception in case of failure

getEditableLocaleIds() public method #

Returns an array of the editable locale IDs.

public array getEditableLocaleIds ( )

getEditableLocales() public method #

Returns a list of locales that are editable by the current user.

public array getEditableLocales ( )

getIsIntlLoaded() public method #

Returns whether the Intl extension is loaded.

public boolean getIsIntlLoaded ( )
return boolean Whether the Intl extension is loaded.

getLocaleById() public method #

Returns a locale by its ID.

public craft\i18n\Locale getLocaleById ( \craft\i18n\string $localeId )
$localeId string

getPrimarySiteLocale() public method #

Returns the site's primary locale. The primary locale is whatever is listed first in Settings > Locales in the control panel.

public craft\i18n\Locale getPrimarySiteLocale ( )
return craft\i18n\Locale A craft\i18n\Locale object representing the primary locale.

getPrimarySiteLocaleId() public method #

Returns the site's primary locale ID. The primary locale is whatever is listed first in Settings > Locales in the control panel.

public string getPrimarySiteLocaleId ( )
return string The primary locale ID.

getSiteLocaleIds() public method #

Returns an array of the site locale IDs.

public array getSiteLocaleIds ( )
return array An array of locale IDs.

getSiteLocales() public method #

Returns an array of the site locales.

public craft\i18n\Locale[] getSiteLocales ( )
return craft\i18n\Locale[] An array of craft\i18n\Locale objects.

init() public method #

Initializes the component by configuring the default message categories.

public void init ( )

translate() public method #

Translates a message to the specified language.

After translation the message will be formatted using \craft\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.