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 9y 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 4w 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 9% 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://avatars.githubusercontent.com/u/2112911?v=4)[Tigros](/maintainers/Tigros)[@tigros](https://github.com/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

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