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
# Public Properties
Property | Description |
---|---|
allLocaleIds | array – An array of locale IDs. |
allLocales | craft\i18n\Locale[] – An array of craft\i18n\Locale objects. |
appLocaleIds | array – An array of locale IDs. |
appLocales | craft\i18n\Locale[] – An array of craft\i18n\Locale objects. |
behaviors | yii\base\Behavior – List of behaviors attached to this component |
editableLocaleIds | array |
editableLocales | array |
isIntlLoaded | boolean – Whether the Intl extension is loaded. |
messageFormatter | yii\i18n\MessageFormatter – 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 – The primary locale ID. |
siteLocaleIds | array – An array of locale IDs. |
siteLocales | craft\i18n\Locale[] – An array of craft\i18n\Locale objects. |
translations | array – List of yii\i18n\MessageSource configurations or objects. |
# allLocaleIds
- Type
- array
- Default value
null
- Access
- Read-only
An array of locale IDs.
# allLocales
- Type
- craft\i18n\Locale[]
- Default value
null
- Access
- Read-only
An array of craft\i18n\Locale objects.
# appLocaleIds
- Type
- array
- Default value
null
- Access
- Read-only
An array of locale IDs.
# appLocales
- Type
- craft\i18n\Locale[]
- Default value
null
- Access
- Read-only
An array of craft\i18n\Locale objects.
# editableLocaleIds
- Type
- array
- Default value
null
- Access
- Read-only
# editableLocales
- Type
- array
- Default value
null
- Access
- Read-only
# isIntlLoaded
- Type
- boolean
- Default value
null
- Access
- Read-only
Whether the Intl extension is loaded.
# primarySiteLocale
- Type
- craft\i18n\Locale
- Default value
null
- Access
- Read-only
A craft\i18n\Locale object representing the primary locale.
# primarySiteLocaleId
- Type
- string
- Default value
null
- Access
- Read-only
The primary locale ID.
# siteLocaleIds
- Type
- array
- Default value
null
- Access
- Read-only
An array of locale IDs.
# siteLocales
- Type
- craft\i18n\Locale[]
- Default value
null
- Access
- Read-only
An array of craft\i18n\Locale objects.
# Public Methods
Method | Description |
---|---|
__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 an object property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets value of an object property. |
__unset() | Sets an object property to 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. |
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. |
# 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/
.
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/
.
Returns
array – An array of locale IDs.
Throws
- yii\base\Exception
in case of failure
# 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/
.
Returns
craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
Throws
- yii\base\Exception
in case of failure
# getEditableLocaleIds()
Returns an array of the editable locale IDs.
Returns
# getEditableLocales()
Returns a list of locales that are editable by the current user.
Returns
# getIsIntlLoaded()
Returns whether the Intl extension is loaded.
Returns
boolean – Whether the Intl extension is loaded.
# getLocaleById()
Returns a locale by its ID.
Arguments
$localeId
(string)
Returns
# getPrimarySiteLocale()
Returns the site's primary locale. The primary locale is whatever is listed first in Settings > Locales in the control panel.
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.
Returns
string – The primary locale ID.
# getSiteLocaleIds()
Returns an array of the site locale IDs.
Returns
array – An array of locale IDs.
# getSiteLocales()
Returns an array of the site locales.
Returns
craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
# init()
Initializes the component by configuring the default message categories.
# 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.
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.