PHPackages                             moonweft/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. [Localization &amp; i18n](/categories/localization)
4. /
5. moonweft/translatable

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

moonweft/translatable
=====================

A Laravel package for handling multilingual content using table-based translations

1.0.0(7mo ago)01MITPHPPHP ^8.4CI failing

Since Oct 14Pushed 7mo agoCompare

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

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

Moonweft Translatable
=====================

[](#moonweft-translatable)

A Laravel package for handling multilingual content using table-based translations. This package provides a clean and efficient way to manage translations for your Eloquent models without relying on JSON fields.

Features
--------

[](#features)

- **Table-based translations**: Store translations in separate database tables for better query performance and data integrity
- **Eloquent integration**: Seamless integration with Laravel's Eloquent ORM
- **Query scopes**: Built-in query scopes for filtering by translations
- **Custom validation rules**: TranslatableUnique and TranslatableExists validation rules
- **Fallback support**: Automatic fallback to default locale when translation is missing
- **Factory support**: Eloquent Factory macros for creating translated models
- **🌍 Extensive language support**: Supports 70+ mainstream languages including RTL languages
- **🔤 Unicode support**: Full support for Unicode characters and special symbols
- **🌐 Localized validation**: Validation error messages in multiple languages
- **📝 AbstractTranslation**: Base class for translation models without timestamps
- **🛠️ Make Command**: `make:moonweft-model` command for generating complete model structures
- **Comprehensive testing**: Full test coverage with 139 tests

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

[](#installation)

```
composer require moonweft/translatable
```

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

[](#configuration)

The package works out of the box with Laravel's default configuration. No additional configuration is required.

Basic Usage
-----------

[](#basic-usage)

### 1. Create Migration Files

[](#1-create-migration-files)

First, create the main table migration:

```
// database/migrations/create_products_table.php
Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('sku')->unique();
    $table->decimal('price', 10, 2);
    $table->integer('stock')->default(0);
    $table->boolean('is_active')->default(true);
    $table->timestamps();
});
```

Then create the translations table:

```
// database/migrations/create_product_translations_table.php
Schema::create('product_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('product_id')->constrained()->onDelete('cascade');
    $table->string('locale', 10);
    $table->string('name')->nullable();
    $table->string('slug')->nullable();
    $table->text('description')->nullable();
    $table->text('content')->nullable();
    $table->text('specs')->nullable();
    $table->string('meta_title')->nullable();
    $table->text('meta_description')->nullable();
    $table->text('meta_keywords')->nullable();
    $table->text('short_description')->nullable();
    $table->text('features')->nullable();
    $table->text('benefits')->nullable();
    $table->timestamps();

    $table->unique(['product_id', 'locale']);
    $table->unique(['locale', 'slug']);
    $table->index(['locale', 'name']);
    $table->index(['locale', 'slug']);
});
```

### 2. Create Models

[](#2-create-models)

Create your main model:

```
// app/Models/Product.php
