PHPackages                             leinonen/yii2-hostname-language - 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. leinonen/yii2-hostname-language

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

leinonen/yii2-hostname-language
===============================

Simple component which helps to configure the app locale based on the hostname

0.5.0(10y ago)0255MITPHPPHP &gt;=5.5.0

Since Oct 27Pushed 10y ago2 watchersCompare

[ Source](https://github.com/lordthorzonus/yii2-hostname-language)[ Packagist](https://packagist.org/packages/leinonen/yii2-hostname-language)[ Docs](https://github.com/lordthorzonus/yii2-hostname-language)[ RSS](/packages/leinonen-yii2-hostname-language/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Yii2 Hostname Language Component
================================

[](#yii2-hostname-language-component)

[![Build Status](https://camo.githubusercontent.com/009987eeda32727d3128b1cb4673dcb6e8e0ec6feb32f0bf1ebe558d04db4468/68747470733a2f2f7472617669732d63692e6f72672f6c6f726474686f727a6f6e75732f796969322d686f73746e616d652d6c616e67756167652e7376673f6272616e63683d6d6173746572) ](https://travis-ci.org/lordthorzonus/yii2-hostname-language) [![SensioLabsInsight](https://camo.githubusercontent.com/9a1fd3934a389553c4ba1223158ba8470457a83ae8e6cf408ff722481fffd4c8/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f65376438616661302d643838642d343432612d393932652d3430653366383265623563322f6d696e692e706e67)](https://insight.sensiolabs.com/projects/e7d8afa0-d88d-442a-992e-40e3f82eb5c2) [![Latest Stable Version](https://camo.githubusercontent.com/3cebd093ac41e3ad6e1f06875679628a04f55cb4e7dcf241f3f687290042b86d/68747470733a2f2f706f7365722e707567782e6f72672f6c65696e6f6e656e2f796969322d686f73746e616d652d6c616e67756167652f762f737461626c65)](https://packagist.org/packages/leinonen/yii2-hostname-language) [![Total Downloads](https://camo.githubusercontent.com/7db20e391b517690384e2700ff415b4efb5e1625b97a484dd0ac0eee1b77cc1e/68747470733a2f2f706f7365722e707567782e6f72672f6c65696e6f6e656e2f796969322d686f73746e616d652d6c616e67756167652f646f776e6c6f616473)](https://packagist.org/packages/leinonen/yii2-hostname-language) [![Latest Unstable Version](https://camo.githubusercontent.com/10a7083566e99f69ceddfa55465b85385be870b563367685ed823ef45ecbd6fd/68747470733a2f2f706f7365722e707567782e6f72672f6c65696e6f6e656e2f796969322d686f73746e616d652d6c616e67756167652f762f756e737461626c65)](https://packagist.org/packages/leinonen/yii2-hostname-language) [![License](https://camo.githubusercontent.com/5e0bba3f4b927974aff6df76283b035235bd848334353598f1da6dc891263025/68747470733a2f2f706f7365722e707567782e6f72672f6c65696e6f6e656e2f796969322d686f73746e616d652d6c616e67756167652f6c6963656e7365)](https://packagist.org/packages/leinonen/yii2-hostname-language)

This simple component sets the Yii's app locale based on the requests hostname. So for example, if you have **my-awesome-app.com** which is English version of your site and **my-awesome-app.fi** which is Finnish and they both point to the same Yii2 app, this component sets the app language automatically on every request.

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

[](#installation)

Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project.

```
composer require leinonen/yii2-hostname-language
```

### Configuration

[](#configuration)

The component is configured in the main config. The pattern for configuring the hosts is `'hostname' => 'language'`. The scheme of the request (http/https) must be left out.

```
use leinonen\HostnameLanguage\LanguageSelector;

'bootstrap' => ['hostLanguage'],
'components' => [
    'hostLanguage' => [
        'class' => LanguageSelector::class,
        'hosts' => [
             'example.com' => 'fi-FI',
             'foobar.se' => 'se-SE',
      ]
    ]
],
```

URL Manager
-----------

[](#url-manager)

You can also configure a custom URL manager which allows creating urls to another language version of your site. This extends the `\yii\web\UrlManager` so all the normal features are also available.

```
use leinonen\HostnameLanguage\UrlManager;

'components' => [
    'urlManager' => [
      'class' => UrlManager::class,
      'enablePrettyUrl' => true,
      'showScriptName' => false,
    ]
]
```

It then works by feeding a `language` parameter to the URL helper function:

```
Url::to(['site/my-route', 'language' => 'en-US'], true);
```

Remember to set scheme param to **true**, cause you need to create absolute urls. If you are already using an url parameter called language it can easily be changed with the config:

```
'urlManager' => [
    ...
    'languageParam' => 'lang'
]
```

And then:

```
Url::to(['site/my-route', 'lang' => 'en-US'], true);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3849d ago

### Community

Maintainers

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

---

Top Contributors

[![lordthorzonus](https://avatars.githubusercontent.com/u/8689671?v=4)](https://github.com/lordthorzonus "lordthorzonus (14 commits)")

---

Tags

hostnamei18nlanguageyii2locale

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leinonen-yii2-hostname-language/health.svg)

```
[![Health](https://phpackages.com/badges/leinonen-yii2-hostname-language/health.svg)](https://phpackages.com/packages/leinonen-yii2-hostname-language)
```

###  Alternatives

[codemix/yii2-localeurls

Automatic locale/language management for URLs.

4071.3M30](/packages/codemix-yii2-localeurls)[tigrov/yii2-country

Country data for Yii2 using Intl extension and more.

151.1k](/packages/tigrov-yii2-country)[cetver/yii2-languages-dispatcher

Sets the web-application language for the Yii framework 2.0

1029.7k](/packages/cetver-yii2-languages-dispatcher)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)[devgroup/yii2-multilingual

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

152.6k2](/packages/devgroup-yii2-multilingual)

PHPackages © 2026

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