PHPackages                             nh/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. [Localization &amp; i18n](/categories/localization)
4. /
5. nh/translatable

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

nh/translatable
===============

Make a Laravel model translatable

1.1.1(3y ago)132MITPHP

Since Aug 17Pushed 3y ago1 watchersCompare

[ Source](https://github.com/NatachaH/laravel-translatable)[ Packagist](https://packagist.org/packages/nh/translatable)[ RSS](/packages/nh-translatable/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)DependenciesVersions (7)Used By (0)

Installation
============

[](#installation)

Install the package via composer:

```
composer require nh/translatable

```

Publish the config files for the translatable: *You can define the available languages in this config file*

```
php artisan vendor:publish --tag=translatable

```

To make a model translatable, add the **Translatable** trait to your model:

```
use Nh\Translatable\Traits\Translatable;

use Translatable;

```

If you need to customize the insertion for the translation you can add to your model:

```
/**
  * Default translatable option.
  *
  * @var array
  */
protected $translatable = [
    'automatic' => false
];

```

And simply set the translations with the function **$model-&gt;setTranslations(\['en' =&gt; \['name' =&gt; 'English'\],'de' =&gt; \['name' =&gt; 'Deutsch'\]\])**.

Route
-----

[](#route)

To make a route translatable, add the middleware **localization** and the prefixe **{locale}** to your route:

```
Route::middleware('localization')->prefix('{locale}')->get('/', function () {
    return view('welcome');
});

```

And for redirect if url is ** to **

```
Route::middleware('localization')->get('/', function () {
  return redirect()->route('welcome');
});

```

Change the language
-------------------

[](#change-the-language)

You can change the language of the website by using the **localization** route:

```
@foreach (config('translatable.languages') as $key => $value)

    {{ $value }}

@endforeach

```

Javascript
----------

[](#javascript)

If you need to display/hide elements by lang you can use the JS file: *This is a global change in the current page, not for a specific zone !*

```
require('../../vendor/nh/translatable/resources/js/translatable');

```

Then in your html add the links with the class **.lang-toggle** and the data attribute **data-lang**: *To display a different value than the abbreviation of the language, you can add the attribute data-lang-value*

```
The current language is: Français

  FR
  EN

```

And add the data attribute **data-lang** to the content to filter by lang:

```

  Uniquement en Français

  Only in english

  Multiple languages

```

Exemples
========

[](#exemples)

Exemple for a form with multiple translations to insert.

Add Somewhere the language toggle with all the available languages:

```

  {{ config('translatable.default') }}

    @foreach (config('translatable.languages') as $key => $value)
      {{ $value }}
    @endforeach

```

And the inputs for all the available languages:

```
Title

@foreach (Arr::except(config('translatable.languages'), config('translatable.default')) as $key => $value)

@endforeach

```

Events
======

[](#events)

You can use the **TranslationEvent** for dispatch events that happen to the addresses. *You can pass a name, the parent model, the translation model (or null) and the number of translations affected*

```
TranslationEvent::dispatch('my-event', $model, $translation, 1);

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

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

Recently: every ~252 days

Total

6

Last Release

1137d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/24412486?v=4)[Natacha H.](/maintainers/NatachaH)[@NatachaH](https://github.com/NatachaH)

---

Top Contributors

[![NatachaH](https://avatars.githubusercontent.com/u/24412486?v=4)](https://github.com/NatachaH "NatachaH (16 commits)")

### Embed Badge

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

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

###  Alternatives

[smmoosavi/php-gettext

Wrapper for php-gettext by danilo segan. This library provides PHP functions to read MO files even when gettext is not compiled in or when appropriate locale is not present on the system.

1927.0k1](/packages/smmoosavi-php-gettext)

PHPackages © 2026

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