PHPackages                             folklore/eloquent-localizable - 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. folklore/eloquent-localizable

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

folklore/eloquent-localizable
=============================

Laravel 4 and 5 package to add localization capabilities to Eloquent Models

v0.2.2(10y ago)51.3k1MITPHPPHP &gt;=5.4.0

Since Jul 2Pushed 10y ago3 watchersCompare

[ Source](https://github.com/folkloreinc/eloquent-localizable)[ Packagist](https://packagist.org/packages/folklore/eloquent-localizable)[ Docs](http://github.com/Folkloreatelier/eloquent-localizable)[ RSS](/packages/folklore-eloquent-localizable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (1)

Eloquent Localizable
====================

[](#eloquent-localizable)

Simple Laravel 4 and 5 package to add localization capabilities to Eloquent Models

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

[](#installation)

#### Dependencies:

[](#dependencies)

- [Laravel 5.x](https://github.com/laravel/laravel)

#### Installation:

[](#installation-1)

**1-** Require the package with Composer

```
$ composer require folklore/eloquent-localizable
```

Usage
-----

[](#usage)

#### Configuration

[](#configuration)

This package use a Trait to add localization capabilities to your Eloquent modal. Basically it will add a `locales` relation to your model and provide a sync method for easy saving.

For example, if you have a `Page` model and you would like to add localized `title`, `description`. You first add the trait to your `Page` class.

```
use Folklore\EloquentLocalizable\LocalizableTrait;

class Page extends Eloquent {

    use LocalizableTrait;

}
```

By default the trait will look for a `[MODEL_NAME]Locale` model. So in this example, it will looks for a `PageLocale`. Just create a `PageLocale` class next to your `Page` model.

```
use Folklore\EloquentLocalizable\LocaleModel;

class PageLocale extends LocaleModel {

    protected $table = 'pages_locales';

}
```

You can change the locale model class by overiding the `getLocaleModelClass` method.

```
use Folklore\EloquentLocalizable\LocalizableTrait;

class Page extends Eloquent {

    use LocalizableTrait;

    protected function getLocaleModelClass()
    {
        return 'App\Models\CustomLocaleModel';
    }

}
```

You also need to create the table for you localization. Following the example, we will create a migration for a `pages_locales` table.

```
Schema::create('pages_locales', function(Blueprint $table)
{
	$table->increments('id');
	$table->integer('page_id')->unsigned();
	$table->string('locale',2);
	$table->string('title');
	$table->string('description');
	$table->timestamps();

	$table->index('page_id');
	$table->index('locale');
});
```

#### Getting locales

[](#getting-locales)

You can now use the locales relation on your `Page` model.

Getting a page with all locales

```
$page = Page::with('locales')->first();

//Getting the title for a specific locale
echo $page->locales->fr->title;

//Looping through all locales
foreach($page->locales as $locale)
{
    echo $locale->locale.': '.$locale->title;
}
```

Getting a page with a specific locale

```
$page = Page::withLocale('fr')->first();

//Getting a the title
echo $page->locale->fr->title;
```

If you want to always include the locales when fetching a page.

```
use Folklore\EloquentLocalizable\LocalizableTrait;

class Page extends Eloquent {

    use LocalizableTrait;

    protected $with = ['locales'];

}
```

#### Saving locales

[](#saving-locales)

You can use the `syncLocales` method to save your locales.

```
$locales = array(
    'en' => array(
        'title' => 'A page',
        'description' => 'This is the description of this page'
    ),
    'fr' => array(
        'title' => 'Une page',
        'description' => 'Ceci est la description de cette page'
    )
);

//or

$locales = array(
    array(
        'locale' => 'en',
        'title' => 'A page',
        'description' => 'This is the description of this page'
    ),
    array(
        'locale' => 'fr',
        'title' => 'Une page',
        'description' => 'Ceci est la description de cette page'
    )
);

$page = new Page();
$page->save(); //We need an id for this page, so we save before.

$page->syncLocales($locales);
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

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

Recently: every ~53 days

Total

6

Last Release

3983d ago

### Community

Maintainers

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

---

Top Contributors

[![dmongeau](https://avatars.githubusercontent.com/u/124966?v=4)](https://github.com/dmongeau "dmongeau (8 commits)")

---

Tags

laravellocalizationtranslationeloquentlocaleinternational

### Embed Badge

![Health badge](/badges/folklore-eloquent-localizable/health.svg)

```
[![Health](https://phpackages.com/badges/folklore-eloquent-localizable/health.svg)](https://phpackages.com/packages/folklore-eloquent-localizable)
```

###  Alternatives

[laravel-lang/publisher

Localization publisher for your Laravel application

2167.7M24](/packages/laravel-lang-publisher)[richan-fongdasen/laravel-i18n

Simple route and eloquent localization / translation in Laravel

1296.6k](/packages/richan-fongdasen-laravel-i18n)[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)

PHPackages © 2026

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