PHPackages                             yiimaker/yii2-translatable - 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. yiimaker/yii2-translatable

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

yiimaker/yii2-translatable
==========================

Translatable behavior aggregates logic of linking translations to the primary model

v1.0.2(6y ago)1534.0k↓33.3%1[1 issues](https://github.com/yiimaker/yii2-translatable/issues)[2 PRs](https://github.com/yiimaker/yii2-translatable/pulls)1BSD-3-ClausePHP

Since Apr 22Pushed 3y ago3 watchersCompare

[ Source](https://github.com/yiimaker/yii2-translatable)[ Packagist](https://packagist.org/packages/yiimaker/yii2-translatable)[ RSS](/packages/yiimaker-yii2-translatable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (8)Used By (1)

[![Stand With Ukraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://stand-with-ukraine.pp.ua)

 [ ![](https://avatars1.githubusercontent.com/u/24204902) ](https://github.com/yiimaker)

Translatable behavior
=====================

[](#translatable-behavior)

[![Build Status](https://camo.githubusercontent.com/b7267982d2381a8a84e96a3c0d238ec3ba9c2bebec9d2fb2fda7bfd29c1e1c53/68747470733a2f2f7472617669732d63692e6f72672f7969696d616b65722f796969322d7472616e736c617461626c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yiimaker/yii2-translatable)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6bff84337346f997c635434297f4fe576dfadcbbef776da2f1ca258a25fa9054/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7969696d616b65722f796969322d7472616e736c617461626c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yiimaker/yii2-translatable/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/1a245e01cc6bcc188387567d30b6588c0fef97c90ab8afdac4dd3ebbf51d3fd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7969696d616b65722f796969322d7472616e736c617461626c652e737667)](https://packagist.org/packages/yiimaker/yii2-translatable)[![Latest Stable Version](https://camo.githubusercontent.com/59a6180784d6b7fea7c3b085a443ee03061edfeaf2ac72441a4ff7bacfe471b5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7969696d616b65722f796969322d7472616e736c617461626c652e737667)](https://packagist.org/packages/yiimaker/yii2-translatable)[![StandWithUkraine](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg)](https://github.com/vshymanskyy/StandWithUkraine/blob/main/docs/README.md)

Translatable behavior aggregates logic of linking translations to the primary model.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
$ composer require yiimaker/yii2-translatable

```

or add

```
"yiimaker/yii2-translatable": "~1.0"

```

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

Usage
-----

[](#usage)

1. Add behavior to the your primary model

```
public function behaviors()
{
    return [
        // ...
        'translatable' => [
            'class' => TranslatableBehavior::className(),
            // 'translationRelationName' => 'translations',
            // 'translationLanguageAttrName' => 'language',
            // 'attributeNamePattern' => '%name% [%language%]',
            'translationAttributeList' => [
                'title',
                'description',
            ],
        ],
    ];
}
```

2. And use `getTranslation()` or `translateTo()` methods

```
// product is an active record model with translatable behavior
$product = new Product();

// sets translation for default application language
$product->title = 'PhpStrom 2018.1';
$product->description = 'Лицензия PhpStrom IDE версия 2018.1';

// gets translation for English language
$translation = $product->getTranslation('en');
$translation->title = 'PhpStrom 2018.1';
$translation->description = 'License of the PhpStrom IDE version 2018.1';

// sets description for French language
$product->translateTo('fr')->description = 'La licence de PhpStorm IDE la version 2018.1';

$product->insert();
```

`translateTo()` it's just an alias for `getTranslation()` method.

After saving the model you can fetch this model from the database and translatable behavior will fetch all translations automatically.

```
$product = Product::find()
    ->where(['id' => 1])
    ->with('translations')
    ->one()
;

// gets translation for English language
$product->translateTo('en')->description; // License of the PhpStrom IDE version 2018.1
// gets translation for French language
$product->translateTo('fr')->description; // La licence de PhpStorm IDE la version 2018.1

// check whether Ukrainian translation not exists
if (!$product->hasTranslation('uk')) {
    $product->translateTo('uk')->description = 'Ліцензія PhpStrom IDE версія 2018.1';
}

// update Enlish translation
$product->translateTo('en')->title = 'PhpStorm IDE';

$product->update();
```

Tests
-----

[](#tests)

You can run tests with composer command

```
$ composer test

```

or using following command

```
$ codecept build && codecept run

```

Contributing
------------

[](#contributing)

For information about contributing please read [CONTRIBUTING.md](CONTRIBUTING.md).

Sponsoring
----------

[](#sponsoring)

[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/OCmHjEY)

License
-------

[](#license)

[![License](https://camo.githubusercontent.com/4760a73214b833d21a810772a7a2fc471baf3fdcb1f8dee58fed263eeda7dc2a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7969696d616b65722f796969322d7472616e736c617461626c652e737667)](LICENSE)

This project is released under the terms of the BSD-3-Clause [license](LICENSE).

Copyright (c) 2017-2022, Yii Maker

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 80% 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 ~176 days

Total

5

Last Release

2243d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/81dbf9eb881773e58a5472007499612c6e0c93007a75336688a1a21b9630dc1e?d=identicon)[YiiMaker](/maintainers/YiiMaker)

![](https://www.gravatar.com/avatar/9c7243572d974ba9ce049b0a67fd95cf547fd62ea531784d2dfbcc1fbee16806?d=identicon)[greeflas](/maintainers/greeflas)

---

Top Contributors

[![greeflas](https://avatars.githubusercontent.com/u/17636915?v=4)](https://github.com/greeflas "greeflas (8 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (2 commits)")

---

Tags

i18ntranslatabletranslationsyii2yii2-behaviorsyii2-extensiontranslationstranslationtranslatableyii2Behaviorar

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/yiimaker-yii2-translatable/health.svg)

```
[![Health](https://phpackages.com/badges/yiimaker-yii2-translatable/health.svg)](https://phpackages.com/packages/yiimaker-yii2-translatable)
```

###  Alternatives

[omgdef/yii2-multilingual-behavior

Port of the yii-multilingual-behavior for yii

143174.9k9](/packages/omgdef-yii2-multilingual-behavior)[uran1980/yii2-translate-panel

Yii2 Translate Panel makes the translation of your application awesome!

2518.3k1](/packages/uran1980-yii2-translate-panel)[lav45/yii2-translated-behavior

This extension allows you to quickly and simple enough to add translations for any ActiveRecord models.

3742.2k](/packages/lav45-yii2-translated-behavior)[geertw/yii2-translatable-url-rule

A custom URL rule class for Yii 2 which allows to create translated URL rules

1420.3k](/packages/geertw-yii2-translatable-url-rule)

PHPackages © 2026

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