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 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, 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() | 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, according to the Intl extension.
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()
​
DEPRECATED
Deprecated in 4.0.0. The Intl extension is now required.
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.
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.
validateAppLocaleId()
​
- Since
- 3.6.0
Returns whether the given locale ID is a supported app locale ID.
Arguments ​
$localeId
(string)