PHPackages                             organi/translatables - 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. organi/translatables

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

organi/translatables
====================

2.10.0(3y ago)08.1kMITPHPPHP ^8.0

Since Jul 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Organi-BVBA/translatables)[ Packagist](https://packagist.org/packages/organi/translatables)[ Docs](https://github.com/Organi-BVBA/translatables)[ RSS](/packages/organi-translatables/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (12)Versions (22)Used By (0)

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

[](#installation)

You can install the package via composer:

```
composer require organi/translatables
```

You can publish and run the migrations with:

```
php artisan vendor:publish --provider="Organi\Translatables\TranslatablesServiceProvider" --tag="translatables-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --provider="Organi\Translatables\TranslatablesServiceProvider" --tag="translatables-config"
```

This is the contents of the published config file:

```
return [
    'accepted_locales' => [
        'nl', 'en', 'fr', 'de',
    ],
];
```

Usage
-----

[](#usage)

### Make your eloquent model translatable.

[](#make-your-eloquent-model-translatable)

Create a `_translations` table for your model.

```
Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('code');
    $table->timestamps();
});

Schema::create('products_translations', function (Blueprint $table) {
    $table->translations('translations');
    $table->string('name');
    $table->text('description');
});
```

Add the `HasTranslations` trait to your model and a `localizable` array containing the translatable fields.

```
use Organi\Translatables\Traits\HasTranslations;

class Product extends Model
{
    use HasTranslations;

    /**
     * The attributes that should be translatable.
     */
    protected array $localizable = [
        'name', 'description'
    ];
}
```

### Setting translatable fields

[](#setting-translatable-fields)

Now you can add a translation to the name attribute of your model.

```
use Organi\Translatables\Models\Translation;
...
$product->name = Translation::make([
    'nl' => 'Lorem ipsum dolor sit amet',
    'en' => 'Lorem ipsum dolor sit amet',
    'fr' => 'Lorem ipsum dolor sit amet',
]);
```

You can also set an array and the model will turn it in a translation:

```
$product->name = [
    'nl' => 'Lorem ipsum dolor sit amet',
    'en' => 'Lorem ipsum dolor sit amet',
    'fr' => 'Lorem ipsum dolor sit amet',
];
```

You can also set the property to anything other than an array. In this case the default locale of the application will be set with the value.

```
$product->name = 'Lorem ipsum dolor sit amet';

/* returns:
Organi\Translatables\Models\Translation {
  translations: array:4 [
    "nl" => "Lorem ipsum dolor sit amet"
    "en" => ""
    "fr" => ""
  ]
}
*/
```

Or set multiple translations for a single locale

```
$product->setTranslations('nl', [
    'name' => 'Lorem ipsum dolor sit amet',
    'description' => 'Lorem ipsum dolor sit amet',
]);
```

Or set a single translation for a single locale

```
$product->setTranslation('nl', 'name', 'Lorem ipsum dolor sit amet');
```

Or set a single string for all locales

```
$product->setAllLocales('title', 'Lorem ipsum dolor sit amet');
```

### Getting translatable fields

[](#getting-translatable-fields)

Getting a translatable fields will return a `Translation` object.

Converting it to a string will automatically take the value of the active locale. Some options are:

```
echo $product->name;

$dt->title->__toString(),

(string) $dt->title
```

Or you can get a specific locale:

```
echo $product->name->get('en');
```

### Filtering on a translatable fields

[](#filtering-on-a-translatable-fields)

This package provides a `whereTranslation` function.

```
$product = Product::whereTranslation('title', 'Lorem ipsum dolor sit amet')->first();
```

### Ordering on a translatable fields

[](#ordering-on-a-translatable-fields)

This package provides a `orderByTranslation` function. The function has 3 parameters:

- `field`: field that should be used for the ordering
- `locale`: locale that should be used for the ordering
- `direction` (optional defaults to `asc`): `asc` or `desc`

```
$products = Product::orderByTranslation('title')->get();
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~61 days

Total

20

Last Release

1188d ago

Major Versions

1.1.0 → 2.0.02021-09-22

PHP version history (3 changes)1.0.0PHP &gt;=7.0

2.1.0PHP &gt;=7.4

2.6.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8fc65c8eb3455a081de27b4789ee9f50a76e0dc1482d362b307e1143830f814?d=identicon)[organi\_rvk](/maintainers/organi_rvk)

---

Top Contributors

[![robvankeilegom](https://avatars.githubusercontent.com/u/13810300?v=4)](https://github.com/robvankeilegom "robvankeilegom (125 commits)")

---

Tags

eloquenti18nlaraveltranslationslaravelOrganitranslatables

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/organi-translatables/health.svg)

```
[![Health](https://phpackages.com/badges/organi-translatables/health.svg)](https://phpackages.com/packages/organi-translatables)
```

###  Alternatives

[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)

PHPackages © 2026

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