- Set in Yii2 configuration file:
'language' => 'en',
'sourceLanguage' => 'en',
language - default locale.
- Set in params file all the languages do you needs:
'languages' => [
[
'id' => 1,
'url' => 'en',
'locale' => 'en',
'name' => 'English',
'default' => true,
],
[
'id' => 2,
'url' => 'ru',
'locale' => 'ru',
'name' => 'Русский',
],
],
* Use unique integer ID. ** Default - default language (/en /ru - standard, / - default). Do not set any default language so that the script always redirects to the language subfolder.
- Install the extension through composer:
php composer.phar require pjhl/yii2-multilanguage:~0.2
or add this line to the require section of your composer.json
file.
"pjhl/yii2-multilanguage": "^0.2"
- Update your components:
'components' => [
'request' => [
'class' => 'pjhl\multilanguage\components\AdvancedRequest'
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'class' => 'pjhl\multilanguage\components\AdvancedUrlManager',
],
],
- Add .htaccess or nginx config for pretty url.
Skip this step if you do not want to use pretty url.
- Set in Yii2 configuration file:
'on beforeAction' => ['\pjhl\multilanguage\Start', 'run'],
Okay, you have installed the extension. Now you can configure language switching, creating multilingual models and CRUD.