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

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

novius/laravel-translatable
===========================

A Laravel Eloquent model trait for translatable resource

2.0.2(1mo ago)012.3k↓78.2%13AGPL-3.0-or-laterPHPPHP &gt;=8.2CI passing

Since Jul 17Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/novius/laravel-translatable)[ Packagist](https://packagist.org/packages/novius/laravel-translatable)[ Docs](https://github.com/novius/laravel-translatable)[ RSS](/packages/novius-laravel-translatable/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (14)Versions (13)Used By (3)

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

[](#laravel-translatable)

[![Novius CI](https://github.com/novius/laravel-translatable/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/novius/laravel-translatable/actions/workflows/main.yml)[![Packagist Release](https://camo.githubusercontent.com/aa450324b92e64cf0c04d6f5aaf67a438c504e8ea2dddf89d8b13fe91be091bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f766975732f6c61726176656c2d7472616e736c617461626c652e7376673f6d61784167653d31383030267374796c653d666c61742d737175617265)](https://packagist.org/packages/novius/laravel-translatable)[![License: AGPL v3](https://camo.githubusercontent.com/c61341f63648cdd5aba4f7a073b513106a63778c27b15f96c56157642bc943b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4147504c25323076332d626c75652e737667)](http://www.gnu.org/licenses/agpl-3.0)

Introduction
------------

[](#introduction)

A package for making Laravel Eloquent models "translatable" using two fields: `locale` and `locale_parent_id`.

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

[](#requirements)

- Laravel: 10.x, 11.x, 12.x, 13.x
- PHP: 8.2 – 8.5

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

[](#installation)

You can install the package via composer:

```
composer require novius/laravel-translatable
```

You can publish lang files:

```
php artisan vendor:publish --provider="Novius\\LaravelTranslatable\\LaravelTranslatableServiceProvider" --tag=lang
```

Usage
-----

[](#usage)

#### Migrations

[](#migrations)

```
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->translatable(); // Macro provided by the package
    $table->string('title');
    $table->text('text');
    $table->timestamps();
});
```

#### Eloquent Model Trait

[](#eloquent-model-trait)

```
namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use Novius\LaravelTranslatable\Traits\Translatable;

class Post extends Model {
    use Translatable;
    ...
}
```

This trait adds:

- A relation `translations` containing all translations of the model
- A relation `translationsWithDeleted` containing all translations of the model, including those in trash if your model use SoftDelete trait
- A function `translate(string $locale, array $translateAttributes = [])` to translate a model in a new locale
- A function `getTranslation(string $locale, bool $withDeleted = false)` returning the translated model in specified locale or null if it doesn't exist.
- A scope `withLocale($locale)` on the query

```
$post = new Post([
    'title' => 'Français',
]);
$post->save()

$post->translate('en', ['title' => 'English']);
$post->translate('es', ['title' => 'Español']);

// All translation including `fr`
$allTranslations = $post->translations;

$englishTranslation = $post->getTranslation('en');

// $italianTranslation is null
$italianTranslation = $post->getTranslation('it');
```

You can override the `translatableConfig` method of the trait if you want to customize his behavior:

```
namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use Novius\LaravelTranslatable\Traits\Translatable;

class Post extends Model {
    // ...
    public function translatableConfig(): TranslatableModelConfig
    {
        return new TranslatableModelConfig(
            ['fr', 'en'], // Restricted translations to specified locals
            'locale', // The name of de `locale` column
            'locale_parent_id' // The name of de `locale_parent_id` column
        );
    }
}
```

You can override the `translateAttributes` method of the trait if you want to translate some attributes of the model before saving:

```
namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use Novius\LaravelTranslatable\Traits\Translatable;

class Post extends Model {
    use Translatable;

    protected function translateAttributes($parent): void
    {
        $this->some_attribut = $parent->some_attribut.' translated';
    }
    ...
}
```

### Testing

[](#testing)

```
composer run test
```

CS Fixer
--------

[](#cs-fixer)

Lint your code with Laravel Pint using:

```
composer run cs-fix
```

Licence
-------

[](#licence)

This package is under [GNU Affero General Public License v3](http://www.gnu.org/licenses/agpl-3.0.html) or (at your option) any later version.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90% 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

Every ~93 days

Recently: every ~107 days

Total

12

Last Release

54d ago

Major Versions

0.x-dev → 1.0.02024-07-10

1.x-dev → 2.0.02026-02-18

PHP version history (2 changes)0.0.1PHP &gt;=8.1

1.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/341860?v=4)[Novius](/maintainers/novius)[@novius](https://github.com/novius)

---

Top Contributors

[![felixgilles](https://avatars.githubusercontent.com/u/900854?v=4)](https://github.com/felixgilles "felixgilles (27 commits)")[![tony-novius](https://avatars.githubusercontent.com/u/243603340?v=4)](https://github.com/tony-novius "tony-novius (2 commits)")[![tonyyb](https://avatars.githubusercontent.com/u/11064382?v=4)](https://github.com/tonyyb "tonyyb (1 commits)")

---

Tags

laraveltranslationeloquentlaravel-translatabletranslatable

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/novius-laravel-translatable/health.svg)

```
[![Health](https://phpackages.com/badges/novius-laravel-translatable/health.svg)](https://phpackages.com/packages/novius-laravel-translatable)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

854.6k](/packages/waad-laravel-model-metadata)[mozex/laravel-scout-bulk-actions

Import, flush, and queue-import all your Laravel Scout searchable models at once. Auto-discovers models, runs in bulk, tracks progress.

1539.3k](/packages/mozex-laravel-scout-bulk-actions)

PHPackages © 2026

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