Search by

roundly-consulting / translatable-for-laravel

mihaliak

Locale-map (jsonb) translatable attributes with a fallback chain for Eloquent; per-locale slugs via sluggable-for-laravel — native, zero third-party deps.

Package info

github.com/roundly-consulting/translatable-for-laravel

pkg:composer/roundly-consulting/translatable-for-laravel

Fund package maintenance!

Patreon

Statistics

Installs: 9

Dependents: 1

Suggesters: 1

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 18:12 UTC

This package is auto-updated.

Last update: 2026-10-03 18:33:59 UTC


README

Translatable for Laravel — Roundly open source

Latest release Tests Code style Donate Patreon Crypto

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.

Donate to Roundly open source Become a patron on Patreon Donate crypto: BTC, ETH, BNB or SOL

License

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