### Install Translatable for Laravel via Composer Source: https://github.com/roundly-consulting/translatable-for-laravel/blob/main/README.md Install the package using Composer. Requires PHP 8.4 and Laravel 12 or 13. Supported databases: PostgreSQL 12+, MySQL 8.0.23+ (SQLite for tests). SQL Server is not supported. ```bash composer require roundly-consulting/translatable-for-laravel ``` -------------------------------- ### Read and Write Translations in Current Locale Source: https://github.com/roundly-consulting/translatable-for-laravel/blob/main/README.md Create a model with a locale map, set the locale, and use methods like setTranslation, getTranslations, and missingLocales. Falls back to the 'en' locale when the current locale is missing. ```php $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'] ``` -------------------------------- ### Use the Translatable Facade Source: https://github.com/roundly-consulting/translatable-for-laravel/blob/main/README.md Use the Translatable facade for operations not tied to model state, such as using a specific locale for a callback and replacing the translation map from form input. ```php use RoundlyConsulting\Translatable\Facades\Translatable; Translatable::usingLocale('en', fn (): string => $topic->name); // 'Investing' $topic->setTranslations('name', Translatable::fromInput($request->input('name'))); // replaces the map with the form's locales ``` -------------------------------- ### Define a Translatable Model and Migration Source: https://github.com/roundly-consulting/translatable-for-laravel/blob/main/README.md Create a migration with a translatable column and define a model using the HasTranslations trait and Translatable contract. The 'translatable' property lists the translatable attributes. ```php 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; protected $fillable = ['name']; /** @var list */ public array $translatable = ['name']; } ```