PHPackages                             alexkramse/laravel-translatable-table - 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. alexkramse/laravel-translatable-table

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

alexkramse/laravel-translatable-table
=====================================

Provides simple translation for model data via db

1.0.0(1y ago)04MITPHPPHP ^8.1

Since Dec 4Pushed 1y ago1 watchersCompare

[ Source](https://github.com/alexkramse/laravel-translatable-table)[ Packagist](https://packagist.org/packages/alexkramse/laravel-translatable-table)[ RSS](/packages/alexkramse-laravel-translatable-table/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Translatable Table
==========================

[](#laravel-translatable-table)

[![Latest Stable Version](https://camo.githubusercontent.com/53047034349750205a07909926ba756f26a8ca35b8e36b92235c7b1b1ea1ca58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c65786b72616d73652f6c61726176656c2d7472616e736c617461626c652d7461626c652e737667)](https://packagist.org/packages/alexkramse/laravel-translatable-table)[![License](https://camo.githubusercontent.com/7c209d7de279340779e2ccb51f43f0f69622e202deb0eda1ae06f6d5df4e77b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616c65786b72616d73652f6c61726176656c2d7472616e736c617461626c652d7461626c65)](LICENSE)[![Test](https://camo.githubusercontent.com/3406c4e49435a97e098bf61f178a7f803fed71c61351e805e35718b96e5c4392/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c65786b72616d73652f6c61726176656c2d7472616e736c617461626c652d7461626c652f706573742e796d6c3f6272616e63683d6d61696e266c6162656c3d50657374)](https://github.com/alexkramse/laravel-translatable-table/actions/workflows/pest.yml)[![Pint Check](https://camo.githubusercontent.com/3aa47776f0876b6d43cff919f1e8383536829b09ea90dfb23681226eb9e8ea3d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616c65786b72616d73652f6c61726176656c2d7472616e736c617461626c652d7461626c652f70696e742e796d6c3f6272616e63683d6d61696e266c6162656c3d50696e74)](https://github.com/alexkramse/laravel-translatable-table/actions/workflows/pint.yml)

Laravel Translatable Table is a package designed to simplify handling translations stored in a separate table. It provides traits, casts, and utilities to manage and interact with translatable attributes seamlessly.

Supported Laravel Versions
--------------------------

[](#supported-laravel-versions)

The package supports Laravel 8, 9, and 10.

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

[](#installation)

To install the package, use Composer:

```
composer require alexkramse/laravel-translatable-table
```

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

[](#configuration)

After installation, publish the configuration file:

```
php artisan vendor:publish --tag=config --provider="Alexkramse\LaravelTranslatableTable\TranslatableTableServiceProvider"
```

This will create a `config/table-translations.php` file, where you can define supported locales and configure translation settings.

Usage
-----

[](#usage)

### Setting Up a Translatable Model

[](#setting-up-a-translatable-model)

1. Use the `HasTranslatableTable` trait in your model.
2. Define the `translatableTableAttributes` method to specify which attributes are translatable.
3. Ensure your model has a relationship to a translation model.

Example:

```
use Alexkramse\LaravelTranslatableTable\Traits\HasTranslatableTable;

class Post extends Model
{
use HasTranslatableTable;

    protected $fillable = ['slug', 'content'];

    public function translatableTableAttributes(): array
    {
        return ['title', 'description'];
    }
}
```

### Creating a Translation Model

[](#creating-a-translation-model)

For each translatable model, you will need to create a corresponding translation model. For example, for the `Article` model, you will need to create a `ArticleTranslation` model like this:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ArticleTranslation extends Model
{
    use HasFactory;

    protected $guarded = [];
}
```

This model should be associated with the `article_translations` table (or another name depending on your schema). It contains the translated fields and references the original model (in this case, `Article`).

### Migration for Translations

[](#migration-for-translations)

You will also need to create a migration for the `article_translations` table. Here's an example migration:

```
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateArticleTranslationsTable extends Migration
{
    public function up()
    {
        Schema::create('article_translations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('article_id')->constrained()->onDelete('cascade');
            $table->string('locale', 5)->nullable(false)->index();
            $table->string('title')->nullable();
            $table->text('description')->nullable();
            $table->timestamps();

            $table->unique(['article_id', 'locale']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('article_translations');
    }
}
```

### Configuring Locales

[](#configuring-locales)

Update the `config/table-translations.php` file to define the supported locales:

```
return [
    'locales' => [
        'en' => 'English',
        'es' => 'Spanish',
        'fr' => 'French',
    ],
    'translation_model_suffix' => 'Translation',
    'attribute_name' => 'i18n',
];
```

### Interacting with Translations

[](#interacting-with-translations)

You can manage translations directly via the `i18n` attribute on the translatable model:

```
$post = Post::create([
    'slug' => 'example-post',
    'content' => 'This is the content.',
    'i18n' => [
        'en' => ['title' => 'Example Post', 'description' => 'An example post description.'],
        'fr' => ['title' => 'Exemple de publication', 'description' => 'Une description de publication.'],
    ],
]);

// Access translations
$title = $post->title; // Retrieves the title based on the current locale
$translations = $post->i18n; // Retrieves all translations
```

Advanced Features
-----------------

[](#advanced-features)

- **Customizing Locales:** You can dynamically define available locales via the configuration file.
- **Eloquent Events:** Translations are automatically handled during `create` and `update` events.

Notes
-----

[](#notes)

This is the first version of the package. The README and code may contain some inaccuracies or incomplete features. If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

Testing
-------

[](#testing)

To test the package functionality, include your tests using Laravel's testing tools or Pest framework.

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

525d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d1a1dda5b3c56dfc0ac0f5e0e67f7edb92f0a9cd62e8286a76e86f4e47a90ad?d=identicon)[alexkramse](/maintainers/alexkramse)

---

Top Contributors

[![alexkramse](https://avatars.githubusercontent.com/u/42376711?v=4)](https://github.com/alexkramse "alexkramse (18 commits)")

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/alexkramse-laravel-translatable-table/health.svg)

```
[![Health](https://phpackages.com/badges/alexkramse-laravel-translatable-table/health.svg)](https://phpackages.com/packages/alexkramse-laravel-translatable-table)
```

###  Alternatives

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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