xz1mefx / yii2-multilang
Multilanguage tools package
Installs: 91
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
README
The extension is a package of tools to implement multilanguage in Yii2 project:
- Automatically redirects the user to the URL selected (automatically or manually) language and remembers the user selected language
- Automatically collect all new translates into DB
- Has a widget to set a correct hreflang attributes
- Provides a CRUD actions for edit the list of languages and the interface translations
- Has a widget to create language selector (for adminlte theme)
- Has a
@weblang\
alias with current language
Installation
-
The preferred way to install this extension is through composer, run:
php composer.phar require --prefer-dist xz1mefx/yii2-multilang "~1"
-
Add new multilangCache component to common config file:
'multilangCache' => [ 'class' => \xz1mefx\multilang\caching\MultilangCache::className(), ],
-
Execute migration:
php yii migrate --migrationPath=@vendor/xz1mefx/yii2-multilang/migrations --interactive=0
or you can create new migration and extend it, example:
require(Yii::getAlias('@vendor/xz1mefx/yii2-multilang/migrations/m161210_131014_multilang_init.php')); /** * Class m161221_135351_multilang_init */ class m161221_135351_multilang_init extends m161210_131014_multilang_init { }
-
Override components in common config file:
'urlManager' => [ 'class' => \xz1mefx\multilang\web\UrlManager::className(), ], 'request' => [ 'class' => \xz1mefx\multilang\web\Request::className(), ], 'i18n' => [ 'class' => \xz1mefx\multilang\i18n\I18N::className(), ], 'lang' => [ 'class' => \xz1mefx\multilang\components\Lang::className(), ],
-
[not necessary] If you use
iiifx-production/yii2-autocomplete-helper
you need to run: -
Override some components in console config file:
'request' => [ // override common config 'class' => 'yii\console\Request', ], 'urlManager' => [], // override common config 'i18n' => [], // override common config
-
Add HrefLangs widget to page
<head></head>
section in layout(s):<?= \xz1mefx\multilang\widgets\HrefLangs::widget() ?>
-
Add LanguageController (or another) with next code:
use xz1mefx\multilang\actions\language\IndexAction; use xz1mefx\multilang\actions\language\CreateAction; use xz1mefx\multilang\actions\language\UpdateAction; use xz1mefx\multilang\actions\language\DeleteAction; ... /** * @inheritdoc */ public function actions() { return [ 'index' => [ 'class' => IndexAction::className(), // 'theme' => IndexAction::THEME_ADMINLTE, // 'canAdd' => false, // 'canUpdate' => false, // 'canDelete' => false, ], 'create' => [ 'class' => CreateAction::className(), // 'theme' => CreateAction::THEME_ADMINLTE, ], 'update' => [ 'class' => UpdateAction::className(), // 'theme' => UpdateAction::THEME_ADMINLTE, ], 'delete' => [ 'class' => DeleteAction::className(), // 'theme' => DeleteAction::THEME_ADMINLTE, ], ]; }
, where you can change action theme (
THEME_BOOTSTRAP
- by default orTHEME_ADMINLTE
) , view path and access to controls in index action.This controller will control system languages.
-
Add TranslationController (or another) with next code:
use xz1mefx\multilang\actions\translation\IndexAction; use xz1mefx\multilang\actions\translation\UpdateAction; ... /** * @inheritdoc */ public function actions() { return [ 'index' => [ 'class' => IndexAction::className(), // 'theme' => IndexAction::THEME_ADMINLTE, // 'canUpdate' => false, ], 'update' => [ 'class' => UpdateAction::className(), // 'theme' => UpdateAction::THEME_ADMINLTE, ], ]; }
, where you can change action theme (
THEME_BOOTSTRAP
- by default orTHEME_ADMINLTE
) , view path and access to controls in index action.This controller will control interface translations.
-
[not necessary, only for adminlte theme] Add language selector widget into
header ul.nav
:<?= \xz1mefx\multilang\widgets\adminlte\HeaderDropDownLangSelector::widget() ?>
AdminLTE theme you can found in xz1mefx/yii2-adminlte
package.