I18N

Type
Class
Namespace
craft\i18n
Inherits
craft\i18n\I18N » yii\i18n\I18N (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

View source (opens new window)

# Public Properties

Property Description
allLocaleIds array (opens new window) – An array of locale IDs.
allLocales craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
appLocaleIds array (opens new window) – An array of locale IDs.
appLocales craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
behaviors (opens new window) yii\base\Behavior (opens new window) – List of behaviors attached to this component
editableLocaleIds array (opens new window)
editableLocales array (opens new window)
isIntlLoaded boolean (opens new window) – Whether the Intl extension is loaded.
messageFormatter (opens new window) yii\i18n\MessageFormatter (opens new window) – The message formatter to be used to format message via ICU message format.
primarySiteLocale craft\i18n\Locale – A craft\i18n\Locale object representing the primary locale.
primarySiteLocaleId string (opens new window) – The primary locale ID.
siteLocaleIds array (opens new window) – An array of locale IDs.
siteLocales craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
translations (opens new window) array (opens new window) – List of yii\i18n\MessageSource (opens new window) configurations or objects.

# allLocaleIds

Type
array (opens new window)
Default value
null
Access
Read-only

An array of locale IDs.

View source (opens new window)

# allLocales

Type
craft\i18n\Locale[]
Default value
null
Access
Read-only

An array of craft\i18n\Locale objects.

View source (opens new window)

# appLocaleIds

Type
array (opens new window)
Default value
null
Access
Read-only

An array of locale IDs.

View source (opens new window)

# appLocales

Type
craft\i18n\Locale[]
Default value
null
Access
Read-only

An array of craft\i18n\Locale objects.

View source (opens new window)

# editableLocaleIds

Type
array (opens new window)
Default value
null
Access
Read-only

View source (opens new window)

# editableLocales

Type
array (opens new window)
Default value
null
Access
Read-only

View source (opens new window)

# isIntlLoaded

Type
boolean (opens new window)
Default value
null
Access
Read-only

Whether the Intl extension is loaded.

View source (opens new window)

# primarySiteLocale

Type
craft\i18n\Locale
Default value
null
Access
Read-only

A craft\i18n\Locale object representing the primary locale.

View source (opens new window)

# primarySiteLocaleId

Type
string (opens new window)
Default value
null
Access
Read-only

The primary locale ID.

View source (opens new window)

# siteLocaleIds

Type
array (opens new window)
Default value
null
Access
Read-only

An array of locale IDs.

View source (opens new window)

# siteLocales

Type
craft\i18n\Locale[]
Default value
null
Access
Read-only

An array of craft\i18n\Locale objects.

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 an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to 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.
format() (opens new window) Formats a message using yii\i18n\MessageFormatter (opens new window).
getAllLocaleIds() Returns an array of all known locale IDs.
getAllLocales() Returns an array of all known locales.
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/.
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/.
getBehavior() (opens new window) Returns the named behavior object.
getBehaviors() (opens new window) Returns all behaviors attached to this component.
getEditableLocaleIds() Returns an array of the editable locale IDs.
getEditableLocales() Returns a list of locales that are editable by the current user.
getIsIntlLoaded() Returns whether the Intl extension (opens new window) is loaded.
getLocaleById() Returns a locale by its ID.
getMessageFormatter() (opens new window) Returns the message formatter instance.
getMessageSource() (opens new window) Returns the message source for the given category.
getPrimarySiteLocale() Returns the site's primary locale. The primary locale is whatever is listed first in Settings > Locales in the control panel.
getPrimarySiteLocaleId() Returns the site's primary locale ID. The primary locale is whatever is listed first in Settings > Locales in the control panel.
getSiteLocaleIds() Returns an array of the site locale IDs.
getSiteLocales() Returns an array of the site locales.
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.
init() Initializes the component by configuring the default message categories.
off() (opens new window) Detaches an existing event handler from this component.
on() (opens new window) Attaches an event handler to an event.
setMessageFormatter() (opens new window)
translate() Translates a message to the specified language.
trigger() (opens new window) Triggers an event.

# getAllLocaleIds()

Returns an array of all known locale IDs.

If the PHP intl extension (opens new window) 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/.

View source (opens new window)

Returns

array (opens new window) – An array of locale IDs.

# getAllLocales()

Returns an array of all known locales.

See also getAllLocaleIds() View source (opens new window)

Returns

craft\i18n\Locale[] – An array of craft\i18n\Locale objects.

# 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/.

View source (opens new window)

Returns

array (opens new window) – An array of locale IDs.

Throws

# 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/.

View source (opens new window)

Returns

craft\i18n\Locale[] – An array of craft\i18n\Locale objects.

Throws

# getEditableLocaleIds()

Returns an array of the editable locale IDs.

View source (opens new window)

Returns

array (opens new window)

# getEditableLocales()

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

View source (opens new window)

Returns

array (opens new window)

# getIsIntlLoaded()

Returns whether the Intl extension (opens new window) is loaded.

View source (opens new window)

Returns

boolean (opens new window) – Whether the Intl extension is loaded.

# getLocaleById()

Returns a locale by its ID.

View source (opens new window)

Arguments

Returns

craft\i18n\Locale

# getPrimarySiteLocale()

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

View source (opens new window)

Returns

craft\i18n\Locale – A craft\i18n\Locale object representing the primary locale.

# getPrimarySiteLocaleId()

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

View source (opens new window)

Returns

string (opens new window) – The primary locale ID.

# getSiteLocaleIds()

Returns an array of the site locale IDs.

View source (opens new window)

Returns

array (opens new window) – An array of locale IDs.

# getSiteLocales()

Returns an array of the site locales.

View source (opens new window)

Returns

craft\i18n\Locale[] – An array of craft\i18n\Locale objects.

# init()

Initializes the component by configuring the default message categories.

View source (opens new window)

# translate()

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.

View source (opens new window)

Arguments

Returns

string (opens new window) – The translated and formatted message.