PHPackages                             jc-it/yii2-i18n-model - 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. jc-it/yii2-i18n-model

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

jc-it/yii2-i18n-model
=====================

Helpers to work with model translations.

v1.0.2(3y ago)010MITPHPPHP &gt;=8.1

Since Jan 25Pushed 3y ago1 watchersCompare

[ Source](https://github.com/JC-IT/yii2-i18n-model)[ Packagist](https://packagist.org/packages/jc-it/yii2-i18n-model)[ RSS](/packages/jc-it-yii2-i18n-model/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (9)Versions (4)Used By (0)

Helpers to work with model translations for Yii2
================================================

[](#helpers-to-work-with-model-translations-for-yii2)

[![codecov](https://camo.githubusercontent.com/37df8549280dd19bbfdc425ab2b0635c37606af8f090e5ffbf0941f94268baa8/68747470733a2f2f636f6465636f762e696f2f67682f6a632d69742f796969322d6931386e2d6d6f64656c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/jc-it/yii2-i18n-model)[![Continous integration](https://github.com/jc-it/yii2-i18n-model/actions/workflows/ci.yaml/badge.svg)](https://github.com/jc-it/yii2-i18n-model/actions/workflows/ci.yaml)[![Packagist Total Downloads](https://camo.githubusercontent.com/e45ff4054ff32342367d5cc266db2738ad37ffe5407c563ec20c7c18b70cd8c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a632d69742f796969322d6931386e2d6d6f64656c)](https://camo.githubusercontent.com/e45ff4054ff32342367d5cc266db2738ad37ffe5407c563ec20c7c18b70cd8c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a632d69742f796969322d6931386e2d6d6f64656c)[![Packagist Monthly Downloads](https://camo.githubusercontent.com/15493ad753e1a7c0b20906f05d4e99bb71b9dbebaa6123702965f55235d2da4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a632d69742f796969322d6931386e2d6d6f64656c)](https://camo.githubusercontent.com/15493ad753e1a7c0b20906f05d4e99bb71b9dbebaa6123702965f55235d2da4d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6a632d69742f796969322d6931386e2d6d6f64656c)[![GitHub tag (latest by date)](https://camo.githubusercontent.com/cf38ac0c33e9e0c343105f76cd477b889289d9431294a2917bb4289b243bb4f0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6a632d69742f796969322d6931386e2d6d6f64656c)](https://camo.githubusercontent.com/cf38ac0c33e9e0c343105f76cd477b889289d9431294a2917bb4289b243bb4f0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6a632d69742f796969322d6931386e2d6d6f64656c)[![Packagist Version](https://camo.githubusercontent.com/08a3a9c388fa77a88cef1d694beed3d620f3b329a626996b8ed494846db7eeb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a632d69742f796969322d6931386e2d6d6f64656c)](https://camo.githubusercontent.com/08a3a9c388fa77a88cef1d694beed3d620f3b329a626996b8ed494846db7eeb9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a632d69742f796969322d6931386e2d6d6f64656c)

This extension provides a package that implements some traits and behaviors to work with model attribute translations.

```
$ composer require jc-it/yii2-i18n-model
```

or add

```
"jc-it/yii2-i18n-model": "^"

```

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

Configuration
-------------

[](#configuration)

### Active Record model

[](#active-record-model)

Add behavior to you AR model and make sure it has an `i18n` attribute:

```
public function behaviors(): array
{
    return [
        \JCIT\i18n\behaviors\I18nBehavior::class => [
            'class' => \JCIT\i18n\behaviors\I18nBehavior::class,
            'attributes' => [
                '',
            ],
        ]
    ];
}
```

In the rules, just define the rules as you would normally do:

```
public function rules(): array
{
    return [
        [[''], \yii\validators\RequiredValidator::class],
        [[''], \yii\validators\StringValidator::class],
    ];
}
```

In order to set properties or save it first set the locale and then save:

```
$model = new ClassWithI18nBehavior();
$model->locale = 'en-US';
$model-> = 'value en';
$model->save();

$model->locale = 'nl-NL';
$model-> = 'value nl';
$model->save();
```

Fetching values is done automatically to the locale set to the model:

```
$model = ClassWithI18nBehavior::findOne();
$model->locale = 'en-US';
echo $model->; // 'value en'

$model->locale = 'nl-NL';
echo $model->; // 'value nl'
```

### Form model

[](#form-model)

Add the trait to the form model:

```
class FormModel extends \yii\base\Model
{
    use \JCIT\i18n\traits\models\I18nTrait;
}
```

On rendering the form attributes, the attribute name should be like: `i18n[][]`.

TODO
----

[](#todo)

- Fix PHPStan, re-add to `captainhook.json`
    - ```
        {
            "action": "vendor/bin/phpstan",
            "options": [],
            "conditions": []
        },

        ```
- Add tests

Credits
-------

[](#credits)

- [Joey Claessen](https://github.com/joester89)

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/jc-it/yii2-i18n-model/blob/master/LICENSE) for more information.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Every ~21 days

Total

3

Last Release

1215d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/88359ebe0456645a614e563dfbf0dd025b69ef57221050cb9eb31e3eef4dd0f9?d=identicon)[joester89](/maintainers/joester89)

---

Top Contributors

[![joester89](https://avatars.githubusercontent.com/u/9624366?v=4)](https://github.com/joester89 "joester89 (6 commits)")

###  Code Quality

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jc-it-yii2-i18n-model/health.svg)

```
[![Health](https://phpackages.com/badges/jc-it-yii2-i18n-model/health.svg)](https://phpackages.com/packages/jc-it-yii2-i18n-model)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[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)
