PHPackages                             sergmoro1/yii2-lang-switcher - 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. sergmoro1/yii2-lang-switcher

ActiveYii2-extension

sergmoro1/yii2-lang-switcher
============================

Language switcher for a site content.

163PHP

Since Nov 16Pushed 7y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 language switcher
======================

[](#yii2-language-switcher)

Yii has multi-language support, but there are not about content. Content, ordinary, should be on a different sites.

But, for blog, it's not convenient. Simpler translate right in place:

```

  Текст на родном языке.

  Text in native language.

```

So, two classes have defined: `.ru`, `.en`. For current languge - ru-RU, will show html-tags with class `.ru`and tags with class `.en` cleaned up. If has pressed languge switcher, tags with `.ru` cleaned up and with `.en` shows.

Fields with a "short" length (e.g. "title"), language version divided by "/".

This approach is implemented in this little extension for two languages.

Languages can be arbitrary.

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

[](#installation)

In app directory:

```
$ composer require sergmoro1/yii2-lang-switcher "dev-master"
```

Usage
-----

[](#usage)

Register widget in app - `common/config/main.php`: ```

```

In menu place the switcher:

```

```

In a model should be provided getting data for current language. Behavior shoul be connected in a model `/common/models/Post.php`.

```
public function behaviors()
{
    return [
        'LangSwitcher' => ['class' => LangSwitcher::className()],
    ];
}
```

Post content can be shown in `frontend/views/post/view.php`

```

```

and title.

```

```

Data to be displayed uniformly, including RSS, need in the model `common/models/Post.php`to define a method `fields`

```
public function fields()
{
    return [
        'id', 'author_id', 'slug',
        'title' => function ($model) { return $model->splitByLanguage('title'); },
        'content' => function ($model) { return $model->excludeByLanguage('content'); },
        'tags', 'status', 'created_at', 'updated_at',
    ];
}
```

Static content
--------------

[](#static-content)

To apply the proposed approach to static pages, you need to pass the content through the filter of the `excludeByLanguage()`. This requires that `frontend/controllers/SiteController` inherits from controller defined in the extension. ```
use sergmoro1\langswitcher\controllers\Controller;
class SiteController extends Controller
{

```

Remember that in the `sitemap` is also necessary to take into account the language version.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

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/47754c3aa326cd8f607f8207a47193bb3286eac44fded6dd5a312da13358e76c?d=identicon)[sergmoro1](/maintainers/sergmoro1)

---

Top Contributors

[![sergmoro1](https://avatars.githubusercontent.com/u/5292104?v=4)](https://github.com/sergmoro1 "sergmoro1 (18 commits)")

### Embed Badge

![Health badge](/badges/sergmoro1-yii2-lang-switcher/health.svg)

```
[![Health](https://phpackages.com/badges/sergmoro1-yii2-lang-switcher/health.svg)](https://phpackages.com/packages/sergmoro1-yii2-lang-switcher)
```

PHPackages © 2026

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