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

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

initiumlv/laravel-translatable
==============================

Laravel package for translatable models

00PHP

Since Feb 3Pushed 3mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Translatable
====================

[](#laravel-translatable)

A Laravel package that provides easy multi-language (i18n) support for Eloquent models. It automatically manages translations by separating translatable columns into dedicated translation tables, allowing you to store and retrieve model data in multiple languages seamlessly.

Features
--------

[](#features)

- **Automatic Translation Table Management** - Translatable columns are automatically moved to a separate `{table}_translations` table
- **Eloquent Integration** - Use the `HasTranslations` trait for automatic translation joins and locale-aware queries
- **Schema Builder** - Extended schema builder (`TranslatableSchema`) for creating and modifying translatable tables
- **Artisan Commands** - Generate migrations, cache translatable columns, and manage translations via CLI
- **Multi-Locale Support** - Save translations for multiple locales at once
- **Performance Caching** - Cache translatable columns to avoid database queries
- **Laravel 12 Compatible** - Built for modern Laravel applications

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 12.0+

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

[](#installation)

Install the package via Composer:

```
composer require initiumlv/laravel-translatable
```

Publish the configuration file (optional):

```
php artisan vendor:publish --tag="laravel-translatable-config"
```

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

[](#configuration)

The configuration file `config/translatable.php` contains the following options:

```
return [
    // How to handle missing translations: 'strict', 'nullable', or 'fallback'
    'missing_translation_strategy' => 'strict',

    // Path where translatable column cache will be stored
    'cache_path' => 'bootstrap/cache/translatable.php',

    // Automatically regenerate cache after running migrations
    'auto_cache_after_migrate' => true,

    // Suffix used for translation tables (default: _translations)
    'table_suffix' => '_translations',

    // System columns to exclude when detecting translatable columns
    'system_columns' => ['id', 'locale'],
];
```

### Missing Translation Strategies

[](#missing-translation-strategies)

The `missing_translation_strategy` option controls how the package handles records without translations in the current locale:

StrategyBehavior`strict`**Default.** Only returns records that have a translation in the current locale. Uses INNER JOIN - records without translations are excluded.`nullable`Returns all records. Translatable columns will be `NULL` if no translation exists. Uses LEFT JOIN.`fallback`Returns all records. Uses `app.fallback_locale` translation when current locale doesn't exist. Uses LEFT JOIN with COALESCE.Usage
-----

[](#usage)

### Creating Translatable Tables

[](#creating-translatable-tables)

Use the `TranslatableSchema` facade in your migrations to create tables with translatable columns:

```
