Class lajax\languagepicker\Component
Inheritance | lajax\languagepicker\Component » yii\base\Component |
---|---|
Available since version | 1.0 |
Component.
Examples:
Minimal code:
'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'lajax\languagepicker\Component',
'languages' => ['en', 'de', 'fr'] // List of available languages
]
],
Complete example:
'language' => 'en-US',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'lajax\languagepicker\Component',
'languages' => ['en-US', 'de-DE', 'fr-FR'], // List of available languages
'cookieName' => 'language', // Name of the cookie.
'cookieDomain' => 'example.com', // Domain of the cookie.
'expireDays' => 64, // The expiration time of the cookie is 64 days.
'callback' => function() {
if (!\Yii::$app->user->isGuest) {
$user = User::findOne(\Yii::$app->user->id);
$user->language = \Yii::$app->language;
$user->save();
}
}
]
]
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$callback | \lajax\languagepicker\function | - function to execute after changing the language of the site. | lajax\languagepicker\Component |
$cookieDomain | string | The domain that the language cookie is available to. | lajax\languagepicker\Component |
$cookieName | string | Name of the cookie. | lajax\languagepicker\Component |
$expireDays | integer | Expiration date of the cookie storing the language of the site. | lajax\languagepicker\Component |
$languages | array | List of available languages
Formats supported in the pre-defined skins:
|
lajax\languagepicker\Component |
Public Methods
Method | Description | Defined By |
---|---|---|
__construct() | lajax\languagepicker\Component | |
detectLanguage() | Determine language based on UserAgent. | lajax\languagepicker\Component |
init() | lajax\languagepicker\Component | |
initLanguage() | Setting the language of the site. | lajax\languagepicker\Component |
saveLanguage() | Saving language into cookie and database. | lajax\languagepicker\Component |
saveLanguageIntoCookie() | Save language into cookie. | lajax\languagepicker\Component |
Property Details
- function to execute after changing the language of the site.
The domain that the language cookie is available to. For details see the $domain parameter description of PHP setcookie() function.
Name of the cookie.
Expiration date of the cookie storing the language of the site.
List of available languages Formats supported in the pre-defined skins:
['en', 'de', 'es']
['en' => 'English', 'de' => 'Deutsch', 'fr' => 'Français']
['en-US', 'de-DE', 'fr-FR']
['en-US' => 'English', 'de-DE' => 'Deutsch', 'fr-FR' => 'Français']
Method Details
void __construct( $config = [] ) | ||
$config | array | |
throws | \yii\base\InvalidConfigException |
---|
Determine language based on UserAgent.
void detectLanguage( ) |
void init( ) |
Setting the language of the site.
void initLanguage( ) |
Saving language into cookie and database.
static saveLanguage( $language ) | ||
$language | string |
|
Save language into cookie.
void saveLanguageIntoCookie( $language ) | ||
$language | string |