PHPackages                             xerobug/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. [Localization &amp; i18n](/categories/localization)
4. /
5. xerobug/yii2-multilingual

ActiveYii2-extension[Localization &amp; i18n](/categories/localization)

xerobug/yii2-multilingual
=========================

Allows building yii2 apps for multiple languages using regional URL's and domains

010PHP

Since Dec 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/aamirshahzadxerobug/yii2-multilingual)[ Packagist](https://packagist.org/packages/xerobug/yii2-multilingual)[ RSS](/packages/xerobug-yii2-multilingual/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 multilingual component
===========================

[](#yii2-multilingual-component)

Allows building yii2 apps for multiple languages using regional URL's and domains

[![Build Status](https://camo.githubusercontent.com/60f4de4cb40cd6548bd8237db1b2deb8e44c5d5f4a9dd758f51329183e553d4d/68747470733a2f2f7472617669732d63692e6f72672f44657647726f75702d72752f796969322d6d756c74696c696e6775616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/DevGroup-ru/yii2-multilingual)[![codecov.io](https://camo.githubusercontent.com/ca6ce94a65fe306a2a1e929c57c90d5031106f26967470598d2fba11f265fa58/687474703a2f2f636f6465636f762e696f2f6769746875622f44657647726f75702d72752f796969322d6d756c74696c696e6775616c2f636f7665726167652e7376673f6272616e63683d6d6173746572)](http://codecov.io/github/DevGroup-ru/yii2-multilingual?branch=master)

Quick start:

- [Demo Application](https://github.com/DevGroup-ru/yii2-multilingual-demo)
- [GEO detection daemon](https://github.com/DevGroup-ru/sypex-geo-daemon) and [related multilingual provider](https://github.com/DevGroup-ru/yii2-multilingual-sypex-geo-daemon).

**WARNING:** This extension is under active development.

For support - join [DotPlant2 gitter channel](https://gitter.im/DevGroup-ru/dotplant2).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist xerobug/yii2-multilingual "dev-main"

```

or add

```
"xerobug/yii2-multilingual": "dev-main"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

### Configure your application

[](#configure-your-application)

In your `web.php` config add the following components:

```
        // URL Manager is needed to build correct URL's
        'urlManager' => [
            'class' => \DevGroup\Multilingual\components\UrlManager::className(),
            'excludeRoutes' => [
                //'newsletter/index',
                //'newsletter/test',
            ],
            'rules' => [
                '' => 'post/index',
            ],
        ],
        // this is the main language and geo detection component
        'multilingual' => [
            'class' => \DevGroup\Multilingual\Multilingual::className(),
            'default_language_id' => 1,
            // the list of handlers that will try to detect information(see also sypex-geo-daemon provider)
            'handlers' => [
                [
                    'class' => \DevGroup\Multilingual\DefaultGeoProvider::className(),
                    'default' => [
                        'country' => [
                            'name' => 'England',
                            'iso' => 'en',
                        ],
                    ],
                ],
            ],
        ],
        // this is simple storage for Languages configuration
        'filedb' => [
            'class' => 'yii2tech\filedb\Connection',
            'path' => __DIR__ . '/data',
        ],
```

### Creating translatable ActiveRecord

[](#creating-translatable-activerecord)

As our implementation is based on `creocoder/yii2-translatable` - the use creation of multilingual ActiveRecords is very similar.

The main differences from `creocoder2/yii2translatable`:

- no need to set `translationAttributes` - they automatically detected from translation model
- language field is `language_id` of integer type

In your ActiveRecord class(for example `Post`) add trait and behavior:

```
use DevGroup\Multilingual\behaviors\MultilingualActiveRecord;
use DevGroup\Multilingual\traits\MultilingualTrait;

/**
 * Class Post
 * @property integer $author_id
 */
class Post extends \yii\db\ActiveRecord
{
    use MultilingualTrait;

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'multilingual' => [
                'class' => MultilingualActiveRecord::className(),
                'translationPublishedAttribute' => 'is_active',
            ],
        ];
    }

    public static function tableName()
    {
        return '{{%post}}';
    }
}
```

### HrefLang

[](#hreflang)

Add one line into your HEAD section of layout view:

```

```

Tips
----

[](#tips)

1. Remember to take care of language\_id when caching multilingual or translatable content
2. In requests to excluded routes there may be no `language_id`, but probably can be `cookie_language_id`
3. If you want to generate URL's from console application you may need to configure additional params(see )
4. MultilingualTrait adds default conditions to find and is not required for use. But if you don't use it - you must manually configure proper relations.
5. Add indexes to your translation tables, especially for `language_id` and `model_id` pair.

Credits and inspiration sources
-------------------------------

[](#credits-and-inspiration-sources)

- Michael Härtl - author of codemix/yii2-localeurls
- Company BINOVATOR - authors of SypexGeo database and php class
- Alexander Kochetov (@creocoder) - yii2-translatable package

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity27

Early-stage or recently created project

 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/537bcd003430f4460bf33508e6670d0482451f564dc6d241f79e7e99fd7c021a?d=identicon)[amirhost](/maintainers/amirhost)

---

Top Contributors

[![aamirshahzadxerobug](https://avatars.githubusercontent.com/u/20058979?v=4)](https://github.com/aamirshahzadxerobug "aamirshahzadxerobug (2 commits)")

### Embed Badge

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

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

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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