Looking to hire Laravel developers? Try LaraJobs

translatable-for-laravel maintained by roundly-consulting

Description
Locale-map (jsonb) translatable attributes with a fallback chain for Eloquent; per-locale slugs via sluggable-for-laravel — native, zero third-party deps.
Last update
2026/10/05 19:01 (dev-main)
License
Downloads
10

Comments
comments powered by Disqus

Translatable for Laravel

Translatable Eloquent attributes stored as a plain { "en": "…", "sk": "…" } locale map in one json/jsonb column. Reads return the current locale through a configurable fallback chain, so content never renders blank, and per-locale slugs come built in.

Installation

Requires PHP 8.4, Laravel 12 or 13, and any Laravel-supported database.

composer require roundly-consulting/translatable-for-laravel

Usage

Give each translatable attribute one locale-map column and list it on the model:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use RoundlyConsulting\Translatable\Concerns\HasTranslations;
use RoundlyConsulting\Translatable\Contracts\Translatable;

Schema::create('topics', function (Blueprint $table): void {
    $table->id();
    $table->translatable('name');   // a jsonb column
    $table->timestamps();
});

final class Topic extends Model implements Translatable
{
    use HasTranslations;

    /** @var list<string> */
    public array $translatable = ['name'];
}

Read and write in the current locale:

$topic = Topic::create(['name' => ['en' => 'Investing']]);

app()->setLocale('sk');
$topic->name;                                    // 'Investing' — falls back to `en`
$topic->missingLocales('name');                  // ['sk']

$topic->setTranslation('name', 'sk', 'Investovanie')->save();
$topic->name;                                    // 'Investovanie'
$topic->getTranslations('name');                 // ['en' => 'Investing', 'sk' => 'Investovanie']

The facade handles everything that isn't per-model state:

use RoundlyConsulting\Translatable\Facades\Translatable;

Translatable::usingLocale('en', fn (): string => $topic->name);                     // 'Investing'
$topic->setTranslations('name', Translatable::fromInput($request->input('name')));  // clean admin input

Documentation

The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/translatable-for-laravel

Release notes are in CHANGELOG.md. To contribute, see the contributing guide.

Support our work

This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.

License

The MIT License (MIT). Copyright (c) roundly-consulting. See LICENSE.md.