Skip to content

I18N ​

Type
Class
Namespace
craft\i18n
Inherits
craft\i18n\I18N » yii\i18n\I18N » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

View source

Public Properties ​

PropertyDescription
allLocaleIdsarray – An array of locale IDs.
allLocalescraft\i18n\Locale[] – An array of craft\i18n\Locale objects.
appLocaleIdsarray – An array of locale IDs.
appLocalescraft\i18n\Locale[] – An array of craft\i18n\Locale objects.
behaviorsyii\base\Behavior – List of behaviors attached to this component.
editableLocaleIdsarray
editableLocalesarray
isIntlLoadedboolean – Whether the Intl extension is loaded.
messageFormatteryii\i18n\MessageFormatter – The message formatter to be used to format message via ICU message format.
primarySiteLocalecraft\i18n\Locale – A craft\i18n\Locale object representing the primary locale.
primarySiteLocaleIdstring – The primary locale ID.
siteLocaleIdsarray – An array of locale IDs.
siteLocalescraft\i18n\Locale[] – An array of craft\i18n\Locale objects.
translationsarray – List of yii\i18n\MessageSource configurations or objects.

allLocaleIds ​

Type
array
Default value
null
Access
Read-only

An array of locale IDs.

View source

allLocales ​

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

An array of craft\i18n\Locale objects.

View source

appLocaleIds ​

Type
array
Default value
null
Access
Read-only

An array of locale IDs.

View source

appLocales ​

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

An array of craft\i18n\Locale objects.

View source

editableLocaleIds ​

Type
array
Default value
null
Access
Read-only

View source

editableLocales ​

Type
array
Default value
null
Access
Read-only

View source

isIntlLoaded ​

Type
boolean
Default value
null
Access
Read-only

Whether the Intl extension is loaded.

View source

primarySiteLocale ​

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

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

View source

primarySiteLocaleId ​

Type
string
Default value
null
Access
Read-only

The primary locale ID.

View source

siteLocaleIds ​

Type
array
Default value
null
Access
Read-only

An array of locale IDs.

View source

siteLocales ​

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

An array of craft\i18n\Locale objects.

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of a component property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets the value of a component property.
__unset()Sets a component property to be null.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
format()Formats a message using yii\i18n\MessageFormatter.
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()Returns the named behavior object.
getBehaviors()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 is loaded.
getLocaleById()Returns a locale by its ID.
getMessageFormatter()Returns the message formatter instance.
getMessageSource()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()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined for this component.
init()Initializes the component by configuring the default message categories.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
setMessageFormatter()
translate()Translates a message to the specified language.
trigger()Triggers an event.
validateAppLocaleId()Returns whether the given locale ID is a supported app locale ID.

getAllLocaleIds() ​

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

View source

Returns ​

array – An array of locale IDs.

getAllLocales() ​

Returns an array of all known locales.

See also getAllLocaleIds()View source

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

Returns ​

array – 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

Returns ​

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

Throws ​

getEditableLocaleIds() ​

Returns an array of the editable locale IDs.

View source

Returns ​

array

getEditableLocales() ​

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

View source

Returns ​

array

getIsIntlLoaded() ​

Returns whether the Intl extension is loaded.

View source

Returns ​

boolean – Whether the Intl extension is loaded.

getLocaleById() ​

Returns a locale by its ID.

View source

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

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

Returns ​

string – The primary locale ID.

getSiteLocaleIds() ​

Returns an array of the site locale IDs.

View source

Returns ​

array – An array of locale IDs.

getSiteLocales() ​

Returns an array of the site locales.

View source

Returns ​

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

init() ​

Initializes the component by configuring the default message categories.

View source

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

Arguments ​

  • $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).

Returns ​

string – The translated and formatted message.

validateAppLocaleId() ​

Since
3.6.0

Returns whether the given locale ID is a supported app locale ID.

View source

Arguments ​

Returns ​

boolean