PHPackages                             gbksoft/yii2-multilingual - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gbksoft/yii2-multilingual

ActiveYii2-extension

gbksoft/yii2-multilingual
=========================

Multi languages for yii2

015PHP

Since Apr 25Pushed 10y ago2 watchersCompare

[ Source](https://github.com/gbksoft/yii2-multilingual)[ Packagist](https://packagist.org/packages/gbksoft/yii2-multilingual)[ RSS](/packages/gbksoft-yii2-multilingual/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Multilingual Module for Yii 2
=============================

[](#multilingual-module-for-yii-2)

Start
-----

[](#start)

Скачать [composer](http://getcomposer.org/download/).

После запустить

```
php composer.phar require --prefer-dist gbksoft/yii2-multilingual

```

или добавить в composer.json

```
"gbksoft/yii2-multilingual": "*"

```

DB

### Languages table

[](#languages-table)

```
php yii migrate --migrationPath=/path/to/in/yours/project/vendor/gbksoft/yii2-multilingual/src/migrations

```

### Post table

[](#post-table)

```
CREATE TABLE `post` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `is_active` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB

```

### Post translations table

[](#post-translations-table)

```
CREATE TABLE `post_translation` (
  `post_id` int(10) unsigned NOT NULL,
  `language_id` int(10) unsigned NOT NULL,
  `name` varchar(45) NOT NULL,
  `text` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`post_id`,`language_id`),
  KEY `language_id` (`language_id`),
  CONSTRAINT `fk_post_translation_post` FOREIGN KEY (`post_id`) REFERENCES `post` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `post_translation_ibfk_1` FOREIGN KEY (`language_id`) REFERENCES `language` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB

```

### Подключение модуля для редактирования/создания языков

[](#подключение-модуля-для-редактированиясоздания-языков)

```
// config.php
return [
    'modules' => [
        'language' => [
            'class' => \gbksoft\multilingual\Module::class,
        ],
    ]
];

```

### Подключение в entity модель

[](#подключение-в-entity-модель)

```
class Post extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%post}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'ml' => [
                'class' => Multilingual::class,
                'translationModelName' => PostTranslation::class,
                'translationOwnerField' => 'post_id',
                'languageField' => 'language_id',
            ],
        ];
    }
}

```

### Модель переводов

[](#модель-переводов)

```
/**
 * Class PostTranslation
 *
 * @property integer $post_id
 * @property integer $language_id
 * @property string $name
 * @property string $text
 */
class PostTranslation extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%post_translation}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'text', 'post_id', 'language_id'], 'required'],
            [['post_id', 'language_id'], 'unique', 'targetAttribute' => ['post_id', 'language_id']],
            [['name', 'text'], 'safe'],
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPost() {
        return $this->hasOne(Post::class, ['id' => 'post_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getLanguage() {
        return $this->hasOne(Language::class, ['id' => 'language_id']);
    }
}

```

### Использование в котроллере

[](#использование-в-котроллере)

```
/* in post array
 [
    'Post' => [ formName())
        'en-EN' => [
            'name' => '999999',
            'text' => '9999997777'
        ],
        'ru-RU' => [
            'name' => '777777',
            'text' => '8888888'
        ],
    ]
]
 */
$post->saveTranslations(\Yii::$app->request->post());

$post->getTranslation('en-EN')->one(); // en language
$post->getTranslation()->one(); // default language (Yii::$app->language)
$post->getTranslations()->all(); // all languages

```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a4888a045a33acc8c0385473d3636e41e779e851dd08a3ae96775fa4e1314356?d=identicon)[Altamira](/maintainers/Altamira)

---

Top Contributors

[![Dell-](https://avatars.githubusercontent.com/u/6927645?v=4)](https://github.com/Dell- "Dell- (4 commits)")

### Embed Badge

![Health badge](/badges/gbksoft-yii2-multilingual/health.svg)

```
[![Health](https://phpackages.com/badges/gbksoft-yii2-multilingual/health.svg)](https://phpackages.com/packages/gbksoft-yii2-multilingual)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
