PHP code example of webvimark / multilanguage
1. Go to this page and download the library: Download webvimark/multilanguage 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/ */
webvimark / multilanguage example snippets
return [
...
'mlConfig'=>[
'default_language'=>'ru',
'languages'=>[
'ru'=>'Русский',
'en'=>'English',
],
],
...
];
class Page extends ActiveRecord
{
use MultiLanguageTrait;
/**
* @inheritdoc
*/
public function behaviors()
{
return [
...
'mlBehavior'=>[
'class' => MultiLanguageBehavior::className(),
'mlConfig' => [
'db_table' => 'translations_with_string',
'attributes' => ['name'],
'admin_routes' => [
'content/page/update',
'content/page/index',
],
],
],
...
];
}
public function init()
{
MultiLanguageHelper::catchLanguage();
parent::init();
}
'urlManager' => [
'class'=>MultiLanguageUrlManager::className(),
'enablePrettyUrl' => true,
'showScriptName'=>false,
'rules'=>[
'<_c:[\w \-]+>/<id:\d+>'=>'<_c>/view',
'<_c:[\w \-]+>/<_a:[\w \-]+>/<id:\d+>'=>'<_c>/<_a>',
'<_c:[\w \-]+>/<_a:[\w \-]+>'=>'<_c>/<_a>',
'<_m:[\w \-]+>/<_c:[\w \-]+>/<_a:[\w \-]+>'=>'<_m>/<_c>/<_a>',
'<_m:[\w \-]+>/<_c:[\w \-]+>/<_a:[\w \-]+>/<id:\d+>'=>'<_m>/<_c>/<_a>',
],
],
<?= $form->field($model, 'name')
->textInput(['maxlength' => 255])
->widget(MultiLanguageActiveField::className())
php composer.phar