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(2y ago)132MITPHP

Since Aug 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/NatachaH/laravel-translatable)[ Packagist](https://packagist.org/packages/nh/translatable)[ RSS](/packages/nh-translatable/feed)WikiDiscussions master Synced 1w 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 43% 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

1090d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/47361520c40f781d7d5b39e26b3194800a35e89c4819c220ea3eaaaa907c34ec?d=identicon)[NatachaH](/maintainers/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

[symfony/translation

Provides tools to internationalize your application

6.6k836.5M2.1k](/packages/symfony-translation)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[joedixon/laravel-translation

A tool for managing all of your Laravel translations

717911.4k11](/packages/joedixon-laravel-translation)[illuminate/translation

The Illuminate Translation package.

6936.4M495](/packages/illuminate-translation)[lajax/yii2-translate-manager

Translation management extension for Yii 2

227578.8k13](/packages/lajax-yii2-translate-manager)[larswiegers/laravel-translations-checker

Make sure your laravel translations are checked and are included in all languages.

256423.2k2](/packages/larswiegers-laravel-translations-checker)

PHPackages © 2026

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