PHP code example of user1007017 / yii2-language-picker
1. Go to this page and download the library: Download user1007017/yii2-language-picker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
user1007017 / yii2-language-picker example snippets
'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'user1007017\languagepicker\Component',
'languages' => ['en', 'de', 'fr'] // List of available languages (icons only)
]
],
'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'user1007017\languagepicker\Component', // List of available languages (icons and text)
'languages' => ['en' => 'English', 'de' => 'Deutsch', 'fr' => 'Français']
]
],
'language' => 'en-US',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'user1007017\languagepicker\Component',
'languages' => ['en-US', 'de-DE', 'fr-FR'], // List of available languages (icons only)
'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 = \Yii::$app->user->identity;
$user->language = \Yii::$app->language;
$user->save();
}
}
]
],
'language' => 'en',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'user1007017\languagepicker\Component',
'languages' => function () { // List of available languages (icons only)
return array_keys(\user1007017\translatemanager\models\Language::getLanguageNames(true));
}
]
],
'language' => 'en-US',
'bootstrap' => ['languagepicker'],
'components' => [
'languagepicker' => [
'class' => 'user1007017\languagepicker\Component',
'languages' => function () { // List of available languages (icons and text)
return \user1007017\translatemanager\models\Language::getLanguageNames(true);
},
'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 = \Yii::$app->user->identity;
$user->language = \Yii::$app->language;
$user->save();
}
}
]
],
'components' => [
// ...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// your rules go here
],
// ...
],
// ...
]