PHPackages                             tabaoman/laravel-translation - 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. tabaoman/laravel-translation

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

tabaoman/laravel-translation
============================

An i18n solution with Laravel

v0.9.4(6y ago)024MITPHPPHP ^7.2CI failing

Since Nov 5Pushed 6y ago1 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Guide
=====

[](#guide)

[![Total Downloads](https://camo.githubusercontent.com/58ea751b503c1c08fffed024cb94e0be1cbe3d603e61628766197b528b124498/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746162616f6d616e2f6c61726176656c2d7472616e736c6174696f6e2e7376673f6c6162656c3d446f776e6c6f616473267374796c653d666c61742d7371756172652663616368655365636f6e64733d363030)](https://packagist.org/packages/tabaoman/laravel-translation)[![Latest Version](https://camo.githubusercontent.com/5eada116502aee49d5676383343e6f30894b1750c238d372d0097faf64734521/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746162616f6d616e2f6c61726176656c2d7472616e736c6174696f6e2e7376673f6c6162656c3d52656c65617365267374796c653d666c61742d7371756172652663616368655365636f6e64733d363030)](https://packagist.org/packages/tabaoman/laravel-translation)

**A i18n solution with Laravel**

This is a Laravel package for i18n. You just need to create just **ONE** more table to manage **ALL** multi-language texts for your other Eloquent entities.

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

[](#installation)

```
composer require tabaoman/laravel-translation
```

Basic Use
---------

[](#basic-use)

### **Change the new config file 'translation.php'**

[](#change-the-new-config-file-translationphp)

```
return [
    /*
     * The table that restores the multi-language texts
     * NOTES: Avoid to have any timestamp field.
     *        If you need to record the created/updated time, use 'model' as following.
     */
    'table' => 't_language_translate',

    /*
     * An example helper model.
     * It has a higher priority than 'table' if it is not commented out.
     */
    //'model' => \Tabaoman\Translation\Models\LanguageTranslate::class
];
```

### **Create the table**

[](#create-the-table)

**NOTE:** Do NOT create with timestamp fields ('create\_time', 'update\_time' here) if using 'table' in translation config.

```
CREATE TABLE `t_language_translate` (
    `id`            BIGINT(18)  NOT NULL AUTO_INCREMENT,
    `entity_id`     VARCHAR(32) NOT NULL COMMENT 'model id',
    `lang_code`     VARCHAR(18) NOT NULL COMMENT 'language code',
    `text_code`     VARCHAR(18) NOT NULL COMMENT 'text code',
    `content`       LONGTEXT    NOT NULL COMMENT 'text',
    `create_time`   DATETIME    NOT NULL COMMENT 'created time',
    `update_time`   DATETIME    NULL DEFAULT NULL COMMENT 'updated time',
    PRIMARY KEY (`id`),
    UNIQUE KEY unique_trans (`entity_id`, `lang_code`, `text_code`)
) COMMENT='i18n table' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;
```

### **Add trait and a new member variable '$translations' in model class**

[](#add-trait-and-a-new-member-variable-translations-in-model-class)

```
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Tabaoman\Translation\Translation;
class Store extends Model
{
    use Translation;
    protected $casts = ['id' => 'string']; // Sometimes you need this cast

    protected $translations = [
        'name' => 'STORE_NAME' // attribute => text code
        // 'name' => ['code' => 'STORE_NAME'], // Or associate like this
        // 'name' => ['code' => 'STORE_NAME', 'my_key' => 'my_value'] // You can add custom key-value pair for other uses.
    ];

    // ...
}
```

### **Getting translated attributes**

[](#getting-translated-attributes)

```
$store = Store::first();
echo $store->name; // Get with default language setting (App::getLocale())

echo $store->getTranslation('name', 'en'); // Get its English name
App::setLocale('en');
echo $store->name; // Or get its English name after explicitly set app locale
```

### **Saving translated attributes**

[](#saving-translated-attributes)

```
$store = Store::first();
echo $store->name; // 苹果商店

$store->setTranslation('name', 'Apple store', 'en'); // Directly save the English name
App::setLocale('en');
$store->name = 'Apple store'; // Or set its English name after explicitly set app locale
$store->save(); // Optional if there is no mutator for 'name'

$store = Store::first();
echo $store->name; // Apple store

App::setLocale('zh_CN');
echo $store->name; // 苹果商店
```

### **Flatten the i18n atrributes**

[](#flatten-the-i18n-atrributes)

In model class

```
    protected $translations = [
        'name' => 'STORE_NAME' // attribute => text code
        'name_english' => ['code' => 'STORE_NAME', 'locale' => 'en'],  // You are free to define your own language code.
    ];
```

```
$store = Store::first();
echo $store->name;         // 苹果商店
echo $store->name_english; // Apple store
```

Versions
--------

[](#versions)

PackageLaravelPHP**v0.**\*`5.8.* / 6.*``>=7.2`

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

Total

5

Last Release

2316d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/26106017?v=4)[tabaoman](/maintainers/tabaoman)[@tabaoman](https://github.com/tabaoman)

---

Top Contributors

[![tabaoman](https://avatars.githubusercontent.com/u/26106017?v=4)](https://github.com/tabaoman "tabaoman (17 commits)")

---

Tags

laraveli18ndatabasetranslationmultilanguage

### Embed Badge

![Health badge](/badges/tabaoman-laravel-translation/health.svg)

```
[![Health](https://phpackages.com/badges/tabaoman-laravel-translation/health.svg)](https://phpackages.com/packages/tabaoman-laravel-translation)
```

###  Alternatives

[codezero/laravel-unique-translation

Check if a translated value in a JSON column is unique in the database.

186965.1k7](/packages/codezero-laravel-unique-translation)[moharrum/laravel-adminer

Adminer database management tool for your Laravel application.

451.0k](/packages/moharrum-laravel-adminer)[nevadskiy/laravel-translatable

Add translations to your Eloquent models

2120.4k1](/packages/nevadskiy-laravel-translatable)[hpolthof/laravel-translations-db

A database translations implementation for Laravel 5.

545.8k](/packages/hpolthof-laravel-translations-db)[ao/translation-bundle

Doctrine as symfony translation provider + a nice gui for editing translations.

243.7k](/packages/ao-translation-bundle)

PHPackages © 2026

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