PHPackages                             liaosankai/laravel-eloquent-i18n - 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. [Database &amp; ORM](/categories/database)
4. /
5. liaosankai/laravel-eloquent-i18n

ActiveLibrary[Database &amp; ORM](/categories/database)

liaosankai/laravel-eloquent-i18n
================================

v1.2.1(7y ago)05.6k—0%MITPHPPHP ^7.1.3

Since Jul 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/liaosankai/laravel-eloquent-i18n)[ Packagist](https://packagist.org/packages/liaosankai/laravel-eloquent-i18n)[ RSS](/packages/liaosankai-laravel-eloquent-i18n/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

### Requirements

[](#requirements)

- PHP &gt;= 7.0.0
- Laravel &gt;= 5.5.0

### Installation

[](#installation)

You can install the package via composer:

```
composer require liaosankai/laravel-eloquent-i18n

```

### Making a model translatable

[](#making-a-model-translatable)

```
use Illuminate\Database\Eloquent\Model;
use Liaosankai\LaravelEloquentI18n\Models\TranslationTrait;

class Book extends Model
{
    use TranslationTrait;

    public $i18nable = [
        'title',
        'content',
        'author',
    ];
}

```

### Write translations data

[](#write-translations-data)

Set raw attribute

```
$book = new Book();
$book->title = 'raw title';

```

Set single attribute of single locales

```
$book = new Book();
$book->title = 'raw title';
$book->i18n('zh-Hant')->title = '正體中文的標題';
$book->i18n('zh-Hans')->title = '简体中文的标题';
$book->save();

```

Set multiple locales of single attribute

```
$book = new Book();
$book->title = 'raw title';
$book->title = [
    'zh-Hant' => '正體中文的標題',
    'zh-Hans' => '简体中文的标题',
    'en' => 'english title',
];
$book->save();

```

Set multiple attribute of multiple locales

```
$book = new Book();
$book->title = 'raw title';
$book->i18n([
    'zh-Hant' => [
        'title' => '正體中文的標題',
        'content' => '正體中文的內容',
    ],
    'zh-Hans' => [
        'title' => '简体中文的标题',
        'content' => '简体中文的內容',
    ],
    'en' => [
        'title' => 'english title',
        'content' => 'english content',
    ],
])->save();

```

### Read translations data

[](#read-translations-data)

Arrange presence translations data：

```
$book = new Book();
$book->title = 'raw title';
$book->content = 'raw content';
$book->author = 'raw author';
$book->i18n([
    'zh-Hant' => [
        'title' => '正體中文的標題',
        'content' => '正體中文的內容',
    ],
    'zh-Hans' => [
        'title' => '简体中文的标题',
        'content' => '简体中文的內容',
    ],
    'en' => [
        'title' => 'english title',
        'content' => 'english content',
    ],
])->save();

```

i18n() use all locales array if unassigned any locale

```
App::setLocale('zh-Hant');
$book->i18n()->title;
/*
  [
     'zh-Hant' => '正體中文的標題',
     'zh-Hans' => '简体中文的标题',
     'en' => 'english title',
  ]
*/

```

i18n() use assign locale

```
$book->i18n('zh-Hant')->title; // 正體中文的標題
$book->i18n('zh-Hans')->title; // 简体中文的标题
$book->i18n('zh-en')->title; // english title

```

i18n() use app locale if assign locale not found

```
App::setLocale('zh-Hant');
$book->i18n('ja')->title; // 正體中文的標題

```

i18n() use raw data if assign locale attribute not found

```
App::setLocale('zh-Hant');
$book->i18n('zh-Hant')->author; // raw author

```

Use raw data without i18n()

```
$book->title; // raw title
$book->content; // raw content

```

### filter translations data

[](#filter-translations-data)

use model scope where

```
$book->i18nLike([
    'filter' => [
        'title' => 'keywords for title',
        'content' => 'keywords for content'.
    ],
    'locale' => 'zh-Hant',
])->get();

```

### LICENSE

[](#license)

`laravel-eloquent-i18n` is released under the MIT License

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 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 ~6 days

Total

5

Last Release

2844d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/00c4fc8959e532eca722b0bce1a2ee6d24cf52be83739048204a62ae3682db64?d=identicon)[liaosankai](/maintainers/liaosankai)

---

Top Contributors

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

---

Tags

laraveli18ntranslatemodeleloquent

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/liaosankai-laravel-eloquent-i18n/health.svg)

```
[![Health](https://phpackages.com/badges/liaosankai-laravel-eloquent-i18n/health.svg)](https://phpackages.com/packages/liaosankai-laravel-eloquent-i18n)
```

###  Alternatives

[shiftonelabs/laravel-cascade-deletes

Adds application level cascading deletes to Eloquent Models.

163632.1k2](/packages/shiftonelabs-laravel-cascade-deletes)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[phaza/single-table-inheritance

Single Table Inheritance Trait

1515.8k](/packages/phaza-single-table-inheritance)

PHPackages © 2026

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