PHPackages                             nalingia/laravel-i18n - 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. nalingia/laravel-i18n

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

nalingia/laravel-i18n
=====================

An opinionated Laravel package for model internationalisation.

1.1.4(6y ago)1879MITPHPPHP ^7.2CI failing

Since Apr 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/nalingia/laravel-i18n)[ Packagist](https://packagist.org/packages/nalingia/laravel-i18n)[ RSS](/packages/nalingia-laravel-i18n/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (10)Used By (0)

An *opinionated* Laravel package for models internationalisation
================================================================

[](#an-opinionated-laravel-package-for-models-internationalisation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/87a917b456653c860a3acd763d49f7a62ed882283da01c0d85553325e825b7ec/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e616c696e6769612f6c61726176656c2d6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nalingia/laravel-i18n)[![Build Status](https://camo.githubusercontent.com/0166cb8c582b1153da7900e44135f7a92590f090c15e134059017a936a83ded8/68747470733a2f2f7472617669732d63692e636f6d2f6e616c696e6769612f6c61726176656c2d6931386e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/nalingia/laravel-i18n)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/1878f9324db741118ca459e160037ded12f07deb04bcbc40ea769e67dd549270/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e616c696e6769612f6c61726176656c2d6931386e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/nalingia/laravel-i18n)

I18n is an opinionated package to add internationalisation to a Laravel model.

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

[](#installation)

You can install the package via composer:

```
composer require nalingia/laravel-i18n
```

Laravel will discover the related service provider.

Usage
-----

[](#usage)

This package comes with a *ready-to-use* migration to enable your model to be internationalised. To create the migration run

```
 php artisan i18n:table
```

and then

```
 php artisan migrate
```

It has a minimum configuration available. You can publish using

```
 php artisan vendor:publish --provider="Nalingia\I18n\I18nServiceProvider" --tag="config"
```

To enable internationalisation in your models, follow these simple steps:

1. Import `Nalingia\I18n\Traits\HasI18n` trait into you model.
2. Add a public property named `$catalogueAttributes`: it will contains all attributes that will be translated.
3. Add `'catalogueItems'` to model's `$with` array when using Lavavel 5.6 or below. Starting from Laravel 5.7 imported traits can initialize everything needed when a model is booting. HasI18n can append `'catalogueItems'` to `$with` and `$hidden` arrays.

Here's an set up example:

```
use \Nalingia\I18n\Traits\HasI18n;

class Article extends Model {
   use HasI18n;

   public $catalogueAttributes = [
     'title',
     'abstract',
     'content',
   ];
}
```

### Translations management

[](#translations-management)

There are several way to access property localisations but the easiest one is related to the current application locale:

```
$article->title
```

You can also use this method to access a translation:

```
public function getCatalogueItem(string $attribute, string $locale) : string
```

#### Get a catalogue item

[](#get-a-catalogue-item)

Accessing translation for current application locale is as easy as accessing a model attribute:

```
$article->title
// or
$article->abstract
```

If you want to access translation for a different locale, you can call `translate(string $key, string $locale)`:

```
$article->translate('title', 'it')
```

or

```
$article->getCatalogueItem('title', 'it')
```

#### Retrieve all catalogue items

[](#retrieve-all-catalogue-items)

You can get all available catalogue items for a model by calling `getCatalogueItems()` without providing any argument:

```
$article->getCatalogueItems()
```

Or you can use the accessor

```
$article->translations
```

#### Retrieve all available locales

[](#retrieve-all-available-locales)

You can get all available locale for which exist at least one catalogue item by calling `getCatalogueLocales()`:

```
$article
  ->setCatalogueItem('title', 'en', 'English title')
  ->setCatalogueItem('abstract', 'en', 'English abstract')
  ->setCatalogueItem('title', 'it', 'Italian title')
  ->setCatalogueItem('abstract', 'it', 'Italian abstract')
  ->setCatalogueItem('abstract', 'de', 'German abstract');

$article->getCatalogueLocales(); // ['it', 'en', 'de']
```

#### Setting a catalogue item

[](#setting-a-catalogue-item)

Setting translation for current application locale is as easy as setting a model's property:

```
$article->title = 'Super cool title';
// or
$article->abstract = 'Exciting abstract...';
```

If you want to translate in locales different to the application one you can call `setCatalogueItem(string $key, string $locale, $value)`:

```
$article
  ->setCatalogueItem('title', 'en', 'English title')
  ->setCatalogueItem('abstract', 'en', 'English abstract')
  ->setCatalogueItem('title', 'it', 'Italian title')
  ->setCatalogueItem('abstract', 'it', 'Italian abstract');
```

#### Remove a catalotue item

[](#remove-a-catalotue-item)

You can delete a translation for a specific field:

```
public function forgetCatalogueItem(string $key, string $locale);
```

Or, you can delete all translation for a locale:

```
public function forgetCatalogueItemsForLocale(string $locale);
```

### Creating models

[](#creating-models)

You can set catalogue items when creating new model

```
$article = Article::create([
    'title' => [
        'en' => 'English title',
        'it' => 'Italian title',
    ],
    'abstract' => [
        'en' => 'English abstract',
        'it' => 'Italian abstract',
    ],
]);
```

or you can set only catalogue items that match the current application locale by setting the attribute value without providing any locale key. For example:

```
// app()->getLocale() == 'de'

$article = Article::create([
    'title' => 'German title'
    'abstract' => 'German abstract',
]);
```

is the same as

```
$article = Article::create([
    'title' => [
        'de' => 'German title',
    ],
    'abstract' => [
        'de' => 'German abstract',
    ],
]);
```

Change log
----------

[](#change-log)

Please, see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Testing
-------

[](#testing)

You can run the tests with:

```
composer test
```

or

```
vendor/bin/phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

9

Last Release

2538d ago

### Community

Maintainers

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

---

Top Contributors

[![nalingia](https://avatars.githubusercontent.com/u/5793125?v=4)](https://github.com/nalingia "nalingia (30 commits)")

---

Tags

laraveli18normmodeleloquentmultilingualmulti-languagelaravel-i18n

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nalingia-laravel-i18n/health.svg)

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

###  Alternatives

[matchory/elasticsearch

The missing elasticsearch ORM for Laravel!

3059.0k](/packages/matchory-elasticsearch)

PHPackages © 2026

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