PHPackages                             ebrahimhanna/translation-manager - 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. ebrahimhanna/translation-manager

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

ebrahimhanna/translation-manager
================================

Database-driven translation management for Laravel applications with automatic locale support and slug generation

v2.0.0(6mo ago)01MITPHPPHP &gt;=8.0

Since Nov 9Pushed 6mo agoCompare

[ Source](https://github.com/EbrahimHanna580/translation-manager)[ Packagist](https://packagist.org/packages/ebrahimhanna/translation-manager)[ Docs](https://github.com/EbrahimHanna580/translation-manager)[ RSS](/packages/ebrahimhanna-translation-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Laravel Translation Manager
===========================

[](#laravel-translation-manager)

[![Current version](https://camo.githubusercontent.com/b1b940e6e9c14c32776f47e41905b47a0e7c102351ad170d6335bf611ff3f831/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6562726168696d68616e6e612f7472616e736c6174696f6e2d6d616e616765722e7376673f6c6f676f3d636f6d706f736572)](https://packagist.org/packages/ebrahimhanna/translation-manager)[![Monthly Downloads](https://camo.githubusercontent.com/424f6e3aaf2ce3cbac89cf678bb8834067ea345bc6e88f559850e5dcf186e535/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6562726168696d68616e6e612f7472616e736c6174696f6e2d6d616e616765722e737667)](https://packagist.org/packages/ebrahimhanna/translation-manager/stats)[![Total Downloads](https://camo.githubusercontent.com/b16ba8b19c1f59f577f90be5cd4600a4ed8b76c5114a2803e289617b87d91c8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6562726168696d68616e6e612f7472616e736c6174696f6e2d6d616e616765722e737667)](https://packagist.org/packages/ebrahimhanna/translation-manager/stats)[![License](https://camo.githubusercontent.com/f0e6512bfe55100ab9a383624600658688441bd9a1fc77908f2640729553e73d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6562726168696d68616e6e612f7472616e736c6174696f6e2d6d616e616765722e737667)](https://packagist.org/packages/ebrahimhanna/translation-manager)[![PHP Version](https://camo.githubusercontent.com/964851fa62135d520b235bcb87122bbe5180122cdc4064428ef953300276bfc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6562726168696d68616e6e612f7472616e736c6174696f6e2d6d616e616765722e737667)](https://packagist.org/packages/ebrahimhanna/translation-manager)

Overview
--------

[](#overview)

Laravel Translation Management is a powerful, database-driven translation package that simplifies multi-language content management in Laravel applications. Store translations in dedicated database tables with automatic management through Eloquent events.

Features
--------

[](#features)

- **Database-Driven Translations**: Store translations in dedicated tables for dynamic management
- **Multi-Language Support**: Handle unlimited languages with ease
- **Automatic Translation Management**: Translations are saved/updated automatically via Eloquent events
- **Configurable Architecture**: Customize foreign keys, owner keys, and column names per model
- **Automatic Slug Generation**: Generate unique slugs from translatable fields
- **Locale Support**: Automatically store language codes in translation records
- **Route Skipping**: Selectively disable auto-save on specific routes
- **Performance Optimized**: Built-in caching for language lookups
- **Simple Integration**: Just add a trait to your models
- **Zero Dependencies**: Only requires Laravel/Eloquent

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

[](#installation)

Install the package via Composer:

```
composer require ebrahimhanna/translation-manager
```

Publish the configuration file:

```
php artisan vendor:publish --provider="EbrahimHanna\TranslationManager\PackageServiceProvider"
```

This will create `config/laravel-translations.php` with default settings.

Quick Start
-----------

[](#quick-start)

### 1. Create Database Tables

[](#1-create-database-tables)

You need three types of tables:

**Languages table:**

```
Schema::create('languages', function (Blueprint $table) {
    $table->id();
    $table->string('title'); // e.g., "English"
    $table->string('code');  // e.g., "en"
    $table->timestamps();
});
```

**Main model table (e.g., products):**

```
Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('sku')->unique();
    $table->decimal('price', 10, 2);
    // ... other non-translatable fields
    $table->timestamps();
});
```

**Translation table (e.g., products\_translations):**

```
Schema::create('products_translations', function (Blueprint $table) {
    $table->id();
    $table->foreignId('language_id')->constrained('languages')->cascadeOnDelete();
    $table->foreignId('product_id')->constrained('products')->cascadeOnDelete();
    $table->string('locale')->nullable(); // Auto-filled
    $table->string('name');               // Translatable field
    $table->string('slug')->nullable();   // Auto-generated
    $table->text('description')->nullable();
    $table->timestamps();

    $table->unique(['language_id', 'product_id']);
});
```

### 2. Set Up Your Models

[](#2-set-up-your-models)

**Main Model (Product.php):**

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use EbrahimHanna\TranslationManager\Traits\HasTranslations;

class Product extends Model
{
    use HasTranslations;

    protected $fillable = ['sku', 'price', 'stock'];

    protected $translation_model = [
        'model' => ProductTranslation::class,
        'owner_key' => 'product_id',
        'slug' => 'name', // Auto-generate slug from 'name' field
    ];
}
```

**Translation Model (ProductTranslation.php):**

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class ProductTranslation extends Model
{
    protected $fillable = [
        'product_id',
        'language_id',
        'locale',
        'name',
        'slug',
        'description',
    ];
}
```

### 3. Use in Your Application

[](#3-use-in-your-application)

**Store with translations:**

```
// The trait automatically saves translations from the request
Product::create([
    'sku' => 'PROD-001',
    'price' => 99.99,
]);

// Request should contain:
// translations[1][name] = "English Product Name"
// translations[1][description] = "English description"
// translations[2][name] = "اسم المنتج بالعربية"
// translations[2][description] = "وصف باللغة العربية"
```

**Retrieve translations:**

```
$product = Product::find(1);

// Get specific field translation
$englishName = $product->getTranslation(1, 'name');
// or by language code
$arabicName = $product->getTranslation('ar', 'name', 'code');

// Get all translations for a language
$translation = $product->getTranslationsByLanguage(1);
echo $translation->name;
echo $translation->description;
echo $translation->slug; // auto-generated

// Get all translations
$allTranslations = $product->getAllTranslations;
```

Advanced Usage
--------------

[](#advanced-usage)

### Configuration Options

[](#configuration-options)

The `$translation_model` property accepts the following options:

```
protected $translation_model = [
    // Required
    'model' => ProductTranslation::class,

    // Optional - Override global config
    'foreign_key' => 'language_id',              // FK to languages table
    'owner_key' => 'product_id',                 // FK to parent model
    'translations_data_key' => 'translations',   // Request array key
    'locale_column' => 'locale',                 // Column for language code
    'language_code_column' => 'code',            // Languages table code column

    // Optional - Advanced features
    'slug' => 'name',                            // Auto-generate slug from field
    'skip_routes' => ['products.update'],        // Skip auto-save on routes
];
```

### Global Configuration

[](#global-configuration)

Edit `config/laravel-translations.php`:

```
return [
    'language_model' => 'App\Models\Language',
    'foreign_key' => 'language_id',
    'owner_key' => 'model_id',
    'translations_data_key' => 'translations',
    'language_code_column' => 'code',
    'locale_column' => 'locale', // Set to null to disable
];
```

### Form Structure

[](#form-structure)

Create forms with nested arrays using language IDs as keys:

```

    @csrf

    @foreach($languages as $language)

            {{ $language->title }} ({{ $language->code }})

    @endforeach

    Create Product

```

### Manual Translation Management

[](#manual-translation-management)

Use `withTranslations()` for batch operations or when routes are skipped:

```
// Create product and manually add translations
$product = Product::create([
    'sku' => 'PROD-001',
    'price' => 99.99,
]);

$product->withTranslations([
    1 => ['name' => 'English Name', 'description' => 'English description'],
    2 => ['name' => 'اسم عربي', 'description' => 'وصف عربي'],
]);

// Method chaining
Product::create($data)->withTranslations($translations);
```

### Deleting Translations

[](#deleting-translations)

```
// Delete all translations for a specific language
$product->clearTranslations(1); // By language ID
$product->clearTranslations('en', 'code'); // By language code

// Deleting the model cascades to translations
$product->delete(); // All translations are auto-deleted
```

### API Methods

[](#api-methods)

```
// Get single field translation
$name = $product->getTranslation(1, 'name');
$name = $product->getTranslation('en', 'name', 'code');

// Get all fields for a language (returns model or null)
$translation = $product->getTranslationsByLanguage(1);
$translation = $product->getTranslationsByLanguage('en', 'code');

// Get all translations (returns HasMany relationship)
$allTranslations = $product->getAllTranslations;

// Access via Eloquent relationship
$product->translationRelation()->where('locale', 'en')->get();
```

Use Cases
---------

[](#use-cases)

### E-commerce Products

[](#e-commerce-products)

```
protected $translation_model = [
    'model' => ProductTranslation::class,
    'owner_key' => 'product_id',
    'slug' => 'name',
    'locale_column' => 'locale',
];
```

### Blog Posts

[](#blog-posts)

```
protected $translation_model = [
    'model' => PostTranslation::class,
    'owner_key' => 'post_id',
    'slug' => 'title',
];
```

### Categories with Skip Routes

[](#categories-with-skip-routes)

```
protected $translation_model = [
    'model' => CategoryTranslation::class,
    'owner_key' => 'category_id',
    'skip_routes' => ['categories.quick-update'], // Don't auto-save here
];
```

How It Works
------------

[](#how-it-works)

1. **Automatic Saving**: When you save a model, the `saved` event triggers translation management
2. **Request Extraction**: Translations are extracted from the request using the configured key
3. **Language Validation**: Each language ID is validated against the languages table (cached)
4. **Slug Generation**: If configured, unique slugs are generated from the specified field
5. **Locale Storage**: If enabled, language codes are automatically stored
6. **Cascade Delete**: When a model is deleted, all translations are removed

Performance
-----------

[](#performance)

- **Language Caching**: Language lookups are cached in memory to reduce queries
- **Bulk Operations**: Use `withTranslations()` for batch inserts/updates
- **Eager Loading**: Load translations with `->with('translationRelation')`

Example Application
-------------------

[](#example-application)

Check the `/example` directory for a complete working Laravel application with:

- Categories (basic usage)
- Products (with slug generation)
- Posts (with SEO fields)
- Multiple languages
- CRUD operations

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

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 8.0

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. Fork the repository at
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Please ensure:

- Code follows existing patterns and conventions
- Add tests for new features
- Update documentation as needed

Security
--------

[](#security)

If you discover any security-related issues, please report them by emailing  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ebrahim Hanna](https://github.com/EbrahimHanna580)
- [All Contributors](https://github.com/EbrahimHanna580/translation-manager/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/EbrahimHanna580/translation-manager/issues)
- **Discussions**: [GitHub Discussions](https://github.com/EbrahimHanna580/translation-manager/discussions)
- **Email**:

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance69

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/accf9b419dd7868ecf857a586572836654ab0cafd8e9c97a5fdadcec5676b05b?d=identicon)[EbrahimHanna580](/maintainers/EbrahimHanna580)

---

Top Contributors

[![Ebrahim-Hanna-Sync](https://avatars.githubusercontent.com/u/165266973?v=4)](https://github.com/Ebrahim-Hanna-Sync "Ebrahim-Hanna-Sync (29 commits)")

---

Tags

laravellocalizationi18ntranslationseloquentmulti-languagetranslation-managerdatabase translations

### Embed Badge

![Health badge](/badges/ebrahimhanna-translation-manager/health.svg)

```
[![Health](https://phpackages.com/badges/ebrahimhanna-translation-manager/health.svg)](https://phpackages.com/packages/ebrahimhanna-translation-manager)
```

###  Alternatives

[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

80687.6k](/packages/outhebox-laravel-translations)[tomatophp/filament-translations

Manage your translation with DB and cache, you can scan your languages tags like trans(), \_\_(), and get the string inside and translate them use UI.

6230.1k3](/packages/tomatophp-filament-translations)[richan-fongdasen/laravel-i18n

Simple route and eloquent localization / translation in Laravel

1296.6k](/packages/richan-fongdasen-laravel-i18n)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

754.3k2](/packages/omaralalwi-lexi-translate)[erag/laravel-lang-sync-inertia

A powerful Laravel package for syncing and managing language translations across backend and Inertia.js (Vue/React) frontends, offering effortless localization, auto-sync features, and smooth multi-language support for modern Laravel applications.

3812.2k](/packages/erag-laravel-lang-sync-inertia)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
