PHPackages                             h0rseduck/yii2-languages-dispatcher - 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. h0rseduck/yii2-languages-dispatcher

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

h0rseduck/yii2-languages-dispatcher
===================================

Sets the web-application language for the Yii framework 2.0

1.1.5(5y ago)03BSD-3-ClausePHP

Since Jul 14Pushed 5y agoCompare

[ Source](https://github.com/h0rseduck/yii2-languages-dispatcher)[ Packagist](https://packagist.org/packages/h0rseduck/yii2-languages-dispatcher)[ RSS](/packages/h0rseduck-yii2-languages-dispatcher/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (12)Used By (0)

Languages dispatcher
====================

[](#languages-dispatcher)

[![Build Status](https://camo.githubusercontent.com/65673f22ca4e91be82a8f19761c49f49cb913813e827d01d0d57af2dce5aff7b/68747470733a2f2f7472617669732d63692e6f72672f6365747665722f796969322d6c616e6775616765732d646973706174636865722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/cetver/yii2-languages-dispatcher)[![Coverage Status](https://camo.githubusercontent.com/45486e7cc650091291cc5c040f8e9b1ff9cf1e6d53605758011bb135aad69149/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6365747665722f796969322d6c616e6775616765732d646973706174636865722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/cetver/yii2-languages-dispatcher?branch=master)

Sets the web-application language

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

[](#installation)

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

Either run

```
composer require --prefer-dist h0rseduck/yii2-languages-dispatcher

```

or add

```
"h0rseduck/yii2-languages-dispatcher": "^1.0"

```

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

Usage
-----

[](#usage)

Update the web-application configuration file

```
return [
    'bootstrap' => ['languagesDispatcher'],
    'components' => [
        'languagesDispatcher' => [
            'class' => 'h0rseduck\LanguagesDispatcher\Component',
            'languages' => ['en', 'ru'],
            // useful if you want to push the language handler at the beginning of beforeAction event handlers list
            'appendSetLanguageHandler' => false, // defaults to true
            /*
            or
            'languages' => function () {
                return \app\models\Language::find()->select('code')->column();
            },
            */
            // Order is important
            'handlers' => [
                [
                    // Detects a language based on host name
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\HostNameHandler',
                    'request' => 'request', // optional, the Request component ID.
                    'hostMap' => [ // An array that maps hostnames to languages or a callable function that returns it.
                        'en.example.com' => 'en',
                        'ru.example.com' => 'ru'
                    ]
                ],
                [
                    // Detects a language from the query parameter.
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\QueryParamHandler',
                    'request' => 'request', // optional, the Request component ID.
                    'queryParam' => 'language' // optional, the query parameter name that contains a language.
                ],
                [
                    // Detects a language from the session.
                    // Writes a language to the session, regardless of what handler detected it.
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\SessionHandler',
                    'session' => 'session', // optional, the Session component ID.
                    'key' => 'language' // optional, the session key that contains a language.
                ],
                [
                    // Detects a language from the cookie.
                    // Writes a language to the cookie, regardless of what handler detected it.
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\CookieHandler',
                    'request' => 'request', // optional, the Request component ID.
                    'response' => 'response', // optional, the Response component ID.
                    'cookieConfig' => [ // optional, the Cookie component configuration.
                        'class' => 'yii\web\Cookie',
                        'name' => 'language',
                        'domain' => '',
                        'expire' => strtotime('+1 year'),
                        'path' => '/',
                        'secure' => true | false, // depends on Request::$isSecureConnection
                        'httpOnly' => true,
                    ]
                ],
                [
                    // Detects a language from an authenticated user.
                    // Writes a language to an authenticated user, regardless of what handler detected it.
                    // Note: The property "identityClass" of the "User" component must be an instance of "\yii\db\ActiveRecord"
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\UserHandler',
                    'user' => 'user',  // optional, the User component ID.
                    'languageAttribute' => 'language_code' // optional, an attribute that contains a language.
                ],
                [
                    // Detects a language from the "Accept-Language" header.
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\AcceptLanguageHeaderHandler',
                    'request' => 'request', // optional, the Request component ID.
                ],
                [
                    // Detects a language from the "language" property.
                    'class' => 'h0rseduck\LanguagesDispatcher\handlers\DefaultLanguageHandler',
                    'language' => 'en' // the default language.
                    /*
                    or
                    'language' => function () {
                        return \app\models\Language::find()
                            ->select('code')
                            ->where(['is_default' => true])
                            ->createCommand()
                            ->queryScalar();
                    },
                    */
                ]

            ],
        ],
    ],
];
```

Tests
-----

[](#tests)

Run the following commands

```
composer create-project --prefer-source h0rseduck/yii2-languages-dispatcher
cd yii2-languages-dispatcher
vendor/bin/codecept run unit

```

For I18N support, take a look at
--------------------------------

[](#for-i18n-support-take-a-look-at)

-  - Sets the web-application language
-  - Parses and creates URLs containing languages
-  - Provides the configuration for the language selector
-  - The translatable behavior (Active Record)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 78.6% 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.

###  Release Activity

Cadence

Every ~113 days

Recently: every ~191 days

Total

11

Last Release

2087d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4640238?v=4)[h0rseduck](/maintainers/h0rseduck)[@h0rseduck](https://github.com/h0rseduck)

---

Top Contributors

[![cetver](https://avatars.githubusercontent.com/u/1411914?v=4)](https://github.com/cetver "cetver (22 commits)")[![Raven0us](https://avatars.githubusercontent.com/u/7807766?v=4)](https://github.com/Raven0us "Raven0us (5 commits)")[![vuquangthinh](https://avatars.githubusercontent.com/u/1710072?v=4)](https://github.com/vuquangthinh "vuquangthinh (1 commits)")

---

Tags

urllanguageusersessionyii2extensionlocaleactive-recordcookiedefaultquery parameteraccept language header

### Embed Badge

![Health badge](/badges/h0rseduck-yii2-languages-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/h0rseduck-yii2-languages-dispatcher/health.svg)](https://phpackages.com/packages/h0rseduck-yii2-languages-dispatcher)
```

###  Alternatives

[cetver/yii2-languages-dispatcher

Sets the web-application language for the Yii framework 2.0

1029.7k](/packages/cetver-yii2-languages-dispatcher)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[codezero/laravel-localizer

Automatically detect and set an app locale that matches your visitor's preference.

50394.3k4](/packages/codezero-laravel-localizer)[devgroup/yii2-multilingual

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

152.6k2](/packages/devgroup-yii2-multilingual)[tigrov/yii2-country

Country data for Yii2 using Intl extension and more.

151.1k](/packages/tigrov-yii2-country)

PHPackages © 2026

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