PHPackages                             rahmanramsi/laravel-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. rahmanramsi/laravel-translatable

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

rahmanramsi/laravel-translatable
================================

This is my package laravel-translatable

1.0.0(1y ago)05[3 PRs](https://github.com/rahmanramsi/laravel-translatable/pulls)MITPHPPHP ^8.1CI passing

Since May 23Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/rahmanramsi/laravel-translatable)[ Packagist](https://packagist.org/packages/rahmanramsi/laravel-translatable)[ Docs](https://github.com/rahmanramsi/laravel-translatable)[ GitHub Sponsors](https://github.com/rahmanramsi)[ RSS](/packages/rahmanramsi-laravel-translatable/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (8)Versions (7)Used By (0)

Laravel-Translatable
====================

[](#laravel-translatable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bdf138b0291cecfa1f87114331db82f189fda7207a546fc8919f3e4fa9cd6ec8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261686d616e72616d73692f6c61726176656c2d7472616e736c617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rahmanramsi/laravel-translatable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5e390af10257a8a647d0ee4686e590b246f9927b2c6ae969bc1c2a827fec9695/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261686d616e72616d73692f6c61726176656c2d7472616e736c617461626c652f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/rahmanramsi/laravel-translatable/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/051ad6c3776b466bd5e9f5bd9c004fd98d977939bb0de281f18aa6313e1089f6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261686d616e72616d73692f6c61726176656c2d7472616e736c617461626c652f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/rahmanramsi/laravel-translatable/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/c6c67203c155ea168c325def0baa05c5c4bb10896fd5aff326980903d6f9e06f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261686d616e72616d73692f6c61726176656c2d7472616e736c617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rahmanramsi/laravel-translatable)

Laravel Translatable is a package for easily attaching arbitrary translation data to Eloquent Models.

Features
--------

[](#features)

- One-to-many polymorphic relationship allows attaching translated data to Eloquent models without needing to adjust the database schema.

Installation &amp; Setup
------------------------

[](#installation--setup)

You can install the package via composer:

```
composer require rahmanramsi/laravel-translatable
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="translatable-migrations"
php artisan migrate
```

You can publish the config file with:

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

This is the contents of the published config file:

```
return [
    'model' => Translate::class,
];
```

### Making a model translatable

[](#making-a-model-translatable)

The required steps to make a model translatable are:

- First, you need to add the `RahmanRamsi\LaravelTranslatable\HasTranslations` trait.
- Next, you should create a public property $translatable which holds an array with all the names of attributes you wish to make translatable.

Here's an example of a prepared model:

```
use Illuminate\Database\Eloquent\Model;
use RahmanRamsi\LaravelTranslatable\HasTranslations;

class Post extends Model
{
    use HasTranslations;

    public array $translatable = ['title'];
}
```

Basic Usage
-----------

[](#basic-usage)

### Getting and setting translations

[](#getting-and-setting-translations)

First, you must prepare your model as instructed in the [installation instructions](#making-a-model-translatable).

#### Setting a translation

[](#setting-a-translation)

Here's an example, given that name is a translatable attribute:

```
$post->title = 'hello';
```

Changes automatically saved

To set a translation for a specific locale you can use this method:

```
public function setTranslation(string $key, string $locale, string $value)
```

You can set translations for multiple languages with

```
$translations = ['en' => 'hello', 'es' => 'hola'];

$post->setTranslations('title', $translations);
```

#### Getting a translation

[](#getting-a-translation)

The easiest way to get a translation for the current locale is to just get the property for the translated attribute. For example (given that name is a translatable attribute):

```
$post->title;
```

You can also use this method:

```
public function getTranslation(string $key, string $locale, bool $useFallbackLocale = true)
```

##### Getting all translations

[](#getting-all-translations)

You can get all translations by calling getTranslations() without an argument:

```
$post->getTranslations();
```

Or you can use the accessor:

```
$post->translations
```

The methods above will give you back an array that holds all translations, for example:

```
$post->getTranslations('title');
// returns ['en' => 'hello', 'es' => 'hola']
```

The method above returns, all locales. If you only want specific locales, pass that to the second argument of `getTranslations`.

```
public function getTranslations(string $attributeName)
```

Here's an example:

```
$translations = [
    'en' => 'Hello',
    'fr' => 'Bonjour',
    'de' => 'Hallo',
];

$newsItem->setTranslations('hello', $translations);
$newsItem->getTranslations('hello', ['en', 'fr']); // returns ['en' => 'Hello', 'fr' => 'Bonjour']
```

#### Get locales that a model has

[](#get-locales-that-a-model-has)

You can get all locales that a model has by calling locales() without an argument:

```
$translations = ['en' => 'hello', 'es' => 'hola'];
$post->name = $translations;

$post->locales(); // returns ['en', 'es']
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Rahman Ramsi](https://github.com/rahmanramsi)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance68

Regular maintenance activity

Popularity4

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.4% 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

Unknown

Total

1

Last Release

408d ago

### Community

Maintainers

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

---

Top Contributors

[![rahmanramsi](https://avatars.githubusercontent.com/u/48276043?v=4)](https://github.com/rahmanramsi "rahmanramsi (14 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravellaravel-translatable

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-permission

Permission handling for Laravel 12 and up

12.9k102.4M1.4k](/packages/spatie-laravel-permission)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M101](/packages/dedoc-scramble)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[elegantly/laravel-translator

All on one translations management for Laravel

6333.1k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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