PHPackages                             jetcod/laravel-model-translation - 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. jetcod/laravel-model-translation

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

jetcod/laravel-model-translation
================================

Laravel Model Translation simplifies managing model attribute translations in your Laravel applications.

v1.1.0(1y ago)3500MITPHPPHP ^7.4|^8.0

Since Jul 2Pushed 1y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

Laravel Model Translation
=========================

[](#laravel-model-translation)

[![Actions Status](https://github.com/jetcod/laravel-model-translation/actions/workflows/tests.yml/badge.svg?style=for-the-badge&label=%3Cb%3EBuild%3C/b%3E)](https://github.com/jetcod/laravel-model-translation/actions)

[![Latest Stable Version](https://camo.githubusercontent.com/5a7e1ef9d81ca8735530287a618550ada74c9d153dba351763204513aef4bcbf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6574636f642f6c61726176656c2d6d6f64656c2d7472616e736c6174696f6e3f6c6162656c3d4c6174657374253230537461626c6525323056657273696f6e)](https://packagist.org/packages/jetcod/laravel-model-translation)[![Total Downloads](https://camo.githubusercontent.com/6614493ff422b0a7938947a7410e7f1e97700fe35f514b3a1a0ac21731a0a1a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6574636f642f6c61726176656c2d6d6f64656c2d7472616e736c6174696f6e3f6c6162656c3d546f74616c253230446f776e6c6f616473)](https://packagist.org/packages/jetcod/laravel-model-translation)[![License](https://camo.githubusercontent.com/5a98cc646e3fa2d9948de9d15c60068842a28091f72349058129a55d6d46a9ab/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6574636f642f6c61726176656c2d6d6f64656c2d7472616e736c6174696f6e3f6c6162656c3d4c6963656e7365)](https://github.com/jetcod/eloquent-repository/blob/main/LICENSE)

Laravel Translation is a package that provides a simple and efficient way to manage translations in your Laravel applications. It allows you to store translations of all your models attributes in database, making it easy to manage and update translations without modifying language files.

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

[](#installation)

You can install the package via Composer:

```
composer require jetcod/laravel-model-translation
```

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

[](#configuration)

After installing the package, you need to publish the configuration file and migration:

```
php artisan vendor:publish --tag=translation-config
php artisan vendor:publish --tag=translation-migrations
```

Then, run the migration to create the translations table:

```
php artisan migrate
```

In order to avoid conflictig with other packages and database tables, you can customize your database table name in the `config/translation.php` config file:

```
return [
    'database' => [
        'prefix' => env('TRANSLATION_TABLE_PREFIX', 'lt_'),
        'table_name' => env('TRANSLATION_TABLE_NAME', 'translations'),
    ],
];
```

Usage
-----

[](#usage)

### Setup model

[](#setup-model)

First, you need to import the `Jetcode\Laravel\Translation\Traits\HasTranslations` trait in your model and specify the fields you want to translate:

```
use Jetcode\Laravel\Translation\Traits\HasTranslations;

class Post extends Model
{
    use HasTranslations;

    protected const TRANSLATABLE_ATTRIBUTES = ['title', 'content'];
}
```

Alternatively, you can specify the fields in a method in your model class:

```
use Jetcode\Laravel\Translation\Traits\HasTranslations;

class Post extends Model
{
    use HasTranslations;

    protected function getTranslatableAttributes()
    {
        return ['title', 'content'];
    }
}
```

> **NOTE**: The `TRANSLATABLE_ATTRIBUTES` constant or the `getTranslatableAttributes` method return value can be either a string or an array of the model attribute names.

**Defining translatable attributes is optional, but it is recommended to define them.**

### Create a translation

[](#create-a-translation)

Now, you can create translations for the model attributes through the defined relations:

```
// Create a new post with translations
$post = Post::create([
    'title' => 'Hello World',
    'content' => 'This is a post',
]);

// Create a new translation for the post
$post->translation()->saveMany([
    new Translation([
        'locale' => 'fr_FR',
        'key'    => 'title',
        'value'  => 'Bonjour le monde',
    ]),
    new Translation([
        'locale' => 'fr_FR',
        'key'    => 'content',
        'value'  => 'Ceci est un article',
    ]),
]);
```

### Retrieve translated model

[](#retrieve-translated-model)

This package is compatible with Laravel localization system, so the models are translated according to the current locale. All you need to do is to set the appl locale and your model will be translated automatically:

```
$post = Post::find(123);
var_dump($post->title);     // "Hello World"

app()->setLocale('fr_FR');
var_dump($post->title);     // "Bonjour le monde"
```

Alternatively, you can use the `withLocale` method to retrieve the translated model for a specific locale:

```
var_dump($post->withLocale('fr_FR')->title); // "Bonjour le monde"

// Current locale is reset to default afterwards
var_dump($post->title); // "Hello World"
```

Testing
-------

[](#testing)

The package includes tests that you can run using `PHPUnit`:

```
composer test
```

You can also run static analysis with PHPStan:

```
composer phpstan
```

License
-------

[](#license)

This package is open-source software licensed under the [MIT license](LICENSE.md).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Every ~56 days

Total

3

Last Release

566d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4dedaadbfaf607c33c4b02a55eb9e3a4cf5407267d99d4b4eb7b3fe4a4f1e327?d=identicon)[hamidgh83](/maintainers/hamidgh83)

---

Top Contributors

[![hamidgh83](https://avatars.githubusercontent.com/u/3264788?v=4)](https://github.com/hamidgh83 "hamidgh83 (50 commits)")

---

Tags

laravellaravel-translationlocalizationlaravellocalizationlanguagetranslationlocale

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/jetcod-laravel-model-translation/health.svg)

```
[![Health](https://phpackages.com/badges/jetcod-laravel-model-translation/health.svg)](https://phpackages.com/packages/jetcod-laravel-model-translation)
```

###  Alternatives

[codezero/laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

543638.1k4](/packages/codezero-laravel-localized-routes)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[longman/laravel-multilang

Package to integrate multi language (multi locale) functionality in Laravel 5.x

5514.4k1](/packages/longman-laravel-multilang)[awes-io/localization-helper

Package for convenient work with Laravel's localization features

3527.1k4](/packages/awes-io-localization-helper)[jrmajor/fluent

Fluent localization system for PHP

2716.9k5](/packages/jrmajor-fluent)[zachleigh/laravel-lang-bundler

Create Laravel translations bundles.

2512.5k](/packages/zachleigh-laravel-lang-bundler)

PHPackages © 2026

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