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
# 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 a component property. |
__isset() (opens new window) | Checks if a property is set, i.e. defined and not null. |
__set() (opens new window) | Sets the value of a component property. |
__unset() (opens new window) | Sets a component property to be 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, according to the Intl extension. |
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 for this component. |
init() (opens new window) | 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. |
validateAppLocaleId() | Returns whether the given locale ID is a supported app locale ID. |
# getAllLocaleIds()
Returns an array of all known locale IDs, according to the Intl extension.
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
- yii\base\Exception (opens new window)
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/
.
View source (opens new window)
Returns
craft\i18n\Locale[] – An array of craft\i18n\Locale objects.
Throws
- yii\base\Exception (opens new window)
in case of failure
# getEditableLocaleIds()
Returns an array of the editable locale IDs.
View source (opens new window)
Returns
# getEditableLocales()
Returns a list of locales that are editable by the current user.
View source (opens new window)
Returns
# getIsIntlLoaded()
DEPRECATED
Deprecated in 4.0.0. The Intl extension is now required.
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
$localeId
(string (opens new window))
Returns
# 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.
# 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
$category
(string (opens new window)) – The message category.$message
(string (opens new window)) – The message to be translated.$params
(array (opens new window)) – The parameters that will be used to replace the corresponding placeholders in the message.$language
(string (opens new window)) – The language code (e.g.en-US
,en
).
Returns
string (opens new window) – The translated and formatted message.
# validateAppLocaleId()
- Since
- 3.6.0
Returns whether the given locale ID is a supported app locale ID.
View source (opens new window)
Arguments
$localeId
(string (opens new window))