PHPackages                             tigrov/yii2-language-attributes - 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. tigrov/yii2-language-attributes

ActiveLibrary[Localization &amp; i18n](/categories/localization)

tigrov/yii2-language-attributes
===============================

Behavior for language attributes for Yii2

04PHP

Since May 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Tigrov/yii2-language-attributes)[ Packagist](https://packagist.org/packages/tigrov/yii2-language-attributes)[ RSS](/packages/tigrov-yii2-language-attributes/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-language-attributes
========================

[](#yii2-language-attributes)

Behavior for language attributes for Yii2

Behavior LanguageAttributes is adding possibility to localize ActiveRecord model. It is finding a model field for application language.

E.g. we have table with language fields: `name_en`, `name_ru`, `name_zh_cn` where we store values for each language (en, ru, zh-CN).

When we try to get object field `$model->name;`, if current language of an application is `en-US`the behavior will try to find field `name_en_us` then `name_en`. If current language is `de` and source language is `en`the behavior will try to find field `name_de` then `name` and after the field for source language `name_en`.

When we try to get object field `$model->nameList;`, it will try to get all `name` values for current language. `$model->nameList;` returns array of values.

Using
-----

[](#using)

By default attribute list consist of an attribute `name`

```
/**
 * @property string $name_en
 * @property string $name_ru
 * @property string $name_zh_cn
 */
class Model extends ActiveRecord {
    ...
    public function behaviors()
    {
        return [
            'languageAttribute' => LanguageAttributes::class,
        ];
    }
    ...
}

// this will try to find a value for the current language of an application.
$model->name;
```

Extended example

```
/**
 * @property string $name_en
 * @property string $name_ru
 * @property string $name_zh_cn
 * @property string $field_en
 * @property string $field_ru
 * @property string $field_zh_cn
 * @property string $status
 */
class Model extends ActiveRecord {
    ...
    public function behaviors()
    {
        return [
            'languageAttribute' => [
                'class' => LanguageAttributes::class,
                'attributes' => ['name', 'field'],
                'languages' => ['en', 'ru', 'zh_cn'],
                'query' => ['where' => ['status' => 'active']],
                'sort' => true,
            ]
        ];
    }
    ...
}

// Try to find values for the current language of an application.
$model->name;
$model->field;

// Get list of all values from a model table for the current language
$model->nameList;
$model->fieldList;

// Copy all language values from $model2->name to $model->name
$model->copyValue($model2, 'name');

// Copy all language values from $model2->field2 to $model->field
$model->copyValue($model2, 'field2', 'field');
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/77d285672dec831b7ce5746ab8bb1dd20fffe81fb9d11c232534686706de9697?d=identicon)[Tigros](/maintainers/Tigros)

---

Top Contributors

[![Tigrov](https://avatars.githubusercontent.com/u/8563175?v=4)](https://github.com/Tigrov "Tigrov (1 commits)")

---

Tags

attributeslanguageyii2yii2-behaviors

### Embed Badge

![Health badge](/badges/tigrov-yii2-language-attributes/health.svg)

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

###  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)
