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 3w 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 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity28

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

[php-translation/translator

Translator services

25224.8k5](/packages/php-translation-translator)[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1926.6k1](/packages/smmoosavi-php-gettext)[laradevs/spanish

labels translated to spanish

166.7k](/packages/laradevs-spanish)

PHPackages © 2026

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