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

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

fevrok/laravel-translatable
===========================

This package allows you to translate your models fields.

2.0.0(4y ago)71486[1 PRs](https://github.com/fevrok/laravel-translatable/pulls)MITPHPPHP ^7.1.3|^8.0CI failing

Since Dec 24Pushed 3y ago6 watchersCompare

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

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

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

[](#laravel-translatable)

It's a Laravel model columns translation manager

How it works?
-------------

[](#how-it-works)

[![Laravel Translatable current working model](/images/current_working_model.png)](/images/current_working_model.png)

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

[](#installation)

You can install the package via composer:

```
composer require fevrok/laravel-translatable
```

If you have Laravel 5.5 and up The package will automatically register itself.

else you have to add the service provider to `config/app.php`

```
Fevrok\Translatable\TranslatableServiceProvider::class,
```

publish config file and migration.

```
php artisan vendor:publish --provider="Fevrok\Translatable\TranslatableServiceProvider"
```

next migrate translations table

```
php artisan migrate
```

Setup
-----

[](#setup)

After finishing the installation you can open `config/translatable.php`:

```
return [
   /**
    * Set whether or not the translations is enbaled.
    */
   'enabled' => true,

   /**
    * Select default language
    */
   'locale' => 'en',

];
```

And update your config accordingly.

### Making a model translatable

[](#making-a-model-translatable)

The required steps to make a model translatable are:

- use the `Fevrok\Translatable\Translatable` trait.
- define the model translatable fields in `$translatable` property.

Here's an example of a prepared model:

```
use Fevrok\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;

class Item extends Model
{
    use Translatable;

    /**
      * The attributes that are Translatable.
      *
      * @var array
      */
    protected $translatable = [
        'name',
        'description',
    ];
}
```

### Custom translations model

[](#custom-translations-model)

To get started, publish the assets again this will create new migration update table name to your desire.

CustomTranslation.php

```
class CustomTranslation extends \Fevrok\Translatable\Models\Translation
{
    protected $table = 'custom_translations';
}
```

Add `$translations_model` property and give it to the model you wanna customize,

```
use Illuminate\Database\Eloquent\Model;
use Fevrok\Translatable\Translatable;

class Item extends Model
{
    use Translatable;

    /**
      * The attributes that are Translatable.
      *
      * @var array
      */
    protected $translatable = [
        'name'
    ];

    /**
      * The model used to get translatios.
      *
      * @var string
      */
    protected $translations_model = CustomTranslation::class;
}
```

Usage
-----

[](#usage)

### Eager-load translations

[](#eager-load-translations)

```
// Loads all translations
$posts = Post::with('translations')->get();

// Loads all translations
$posts = Post::all();
$posts->load('translations');

// Loads all translations
$posts = Post::withTranslations()->get();

// Loads specific locales translations
$posts = Post::withTranslations(['en', 'da'])->get();

// Loads specific locale translations
$posts = Post::withTranslations('da')->get();

// Loads current locale translations
$posts = Post::withTranslations('da')->get();
```

### Get default language value

[](#get-default-language-value)

```
echo $post->title;
```

### Get translated value

[](#get-translated-value)

```
echo $post->getTranslatedAttribute('title', 'locale', 'fallbackLocale');
```

If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.

### Translate the whole model

[](#translate-the-whole-model)

```
$post = $post->translate('locale', 'fallbackLocale');
echo $post->title;
echo $post->body;

// You can also run the `translate` method on the Eloquent collection
// to translate all models in the collection.
$posts = $posts->translate('locale', 'fallbackLocale');
echo $posts[0]->title;
```

If you do not define locale, the current application locale will be used. You can pass in your own locale as a string. If you do not define fallbackLocale, the current application fallback locale will be used. You can pass in your own locale as a string. If you want to turn the fallback locale off, pass false. If no values are found for the model for a specific attribute, either for the locale or the fallback, it will set that attribute to null.

### Check if model is translatable

[](#check-if-model-is-translatable)

```
// with string
if (Translatable::translatable(Post::class)) {
    // it's translatable
}

// with object of Model or Collection
if (Translatable::translatable($post)) {
    // it's translatable
}
```

### Set attribute translations

[](#set-attribute-translations)

```
$post = $post->translate('da');
$post->title = 'foobar';
$post->save();
```

This will update or create the translation for title of the post with the locale da. Please note that if a modified attribute is not translatable, then it will make the changes directly to the model itself. Meaning that it will overwrite the attribute in the language set as default.

### Query translatable Models

[](#query-translatable-models)

To search for a translated value, you can use the `whereTranslation` method. For example, to search for the slug of a post, you'd use

```
$page = Page::whereTranslation('slug', 'my-translated-slug');
// Is the same as
$page = Page::whereTranslation('slug', '=', 'my-translated-slug');
// Search only locale en, de and the default locale
$page = Page::whereTranslation('slug', '=', 'my-translated-slug', ['en', 'de']);
// Search only locale en and de
$page = Page::whereTranslation('slug', '=', 'my-translated-slug', ['en', 'de'], false);
```

`whereTranslation` accepts the following parameter:

- `field` the field you want to search in
- `operator` the operator. Defaults to `=`. Also can be the value (Same as [where](https://laravel.com/docs/queries#where-clauses))
- `value` the value you want to search for
- `locales` the locales you want to search in as an array. Leave as `null` if you want to search all locales
- `default` also search in the default value/locale. Defaults to true.

Maintainers
-----------

[](#maintainers)

    [ ![](https://github.com/chadidi.png?v=3&s=150)
 Abdellah Chadidi ](https://github.com/chadidi)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

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 ~183 days

Total

3

Last Release

1596d ago

Major Versions

1.x-dev → 2.0.02021-12-26

PHP version history (2 changes)1.x-devPHP ^5.6.4|^7.0|^8.0

2.0.0PHP ^7.1.3|^8.0

### Community

Maintainers

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

---

Top Contributors

[![chadidi](https://avatars.githubusercontent.com/u/9916806?v=4)](https://github.com/chadidi "chadidi (140 commits)")

---

Tags

databaselaravellaravel-packagephptranslatabletranslationtranslation-managementtranslationstranslatorlaraveltranslatetranslationmodeleloquentmultilinguali8nlaravel-packagetranslatable

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M412](/packages/spatie-laravel-translatable)[rinvex/laravel-tenants

Rinvex Tenants is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.

823.5k10](/packages/rinvex-laravel-tenants)

PHPackages © 2026

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