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

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

anacreation/translatable
========================

Translate Model

00PHP

Since Jun 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/anacreation/translatable)[ Packagist](https://packagist.org/packages/anacreation/translatable)[ RSS](/packages/anacreation-translatable/feed)WikiDiscussions develop Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Overview
========

[](#overview)

This add translation to `Eloquent Model`

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

[](#installation)

```
composer require anacreation/translatable
```

Eloquent model that use the

```
namespace App;

use Anacreation\Translatable\traits\TranslatableTrait;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use TranslatableTrait;
}
```

can use the following APIs

Usage
-----

[](#usage)

Create and update translations
------------------------------

[](#create-and-update-translations)

#### `createModelWithTranslations( array $attributes = [], array $content): Model`

[](#createmodelwithtranslations-array-attributes---array-content-model)

the `$content` has a predefine format

```
$content = [
    "language_code_1"=>[
        "attribute_1" => "value 1",
        "attribute_2" => "value 2",
        "attribute_3" => "value 3",
    ],

    "language_code_2"=>[
        "attribute_1" => "value 4",
        "attribute_2" => "value 5",
        "attribute_3" => "value 6",
    ]
]

$newModel = Model::createModelWithTranslations($attributes, $content);

```

it create a model instance and save the content

#### `updateTranslations(array $content): void`

[](#updatetranslationsarray-content-void)

No matter for create new language transaltion or update existing language. Simple call this funciton. The $content structure is same as above.

Retrieve translation
--------------------

[](#retrieve-translation)

if you have a model with translation as above.

then you can

```
$mode->attribute_1;
```

this will automatically fetch the translation base on your current locale setting.

```
app()->getLocale();
```

### Fallback

[](#fallback)

Then defalut fallback is set to `false`, no fallback if content is `null`.

The fall back system is very simple. if you have set the config fallback\_locale **and** set the eloquent model fallback to `true`

```
$model->fallback = true;
```

then if the translation for particular attribute is `null`. It will try to get the translation for fallback locale.

### Retrieve all translation

[](#retrieve-all-translation)

```
$translation_array = $model->translatables;
```

this will return a array as above. The translation array has structure as below:

```
[
    "language_code_1"=>[
        "attribute_1" => "value 1",
        "attribute_2" => "value 2",
    ],

    "language_code_2"=>[
        "attribute_1" => "value 3",
        "attribute_2" => "value 4",
    ]
]

```

Delete Translation
------------------

[](#delete-translation)

#### `deleteTranslatableAttribute( string $key, string $locale = null ): void`

[](#deletetranslatableattribute-string-key-string-locale--null--void)

This will delete specfic attribute for all or speficied transaltion. If the original translation as below:

```
[
    "language_code_1"=>[
        "attribute_1" => "value 1",
        "attribute_2" => "value 2",
    ],

    "language_code_2"=>[
        "attribute_1" => "value 3",
        "attribute_2" => "value 4",
    ]
]

```

We call

```
    $model->deleteTranslatableAttribute("attribute_2");
```

the translation will become

```
[
    "language_code_1"=>[
        "attribute_1" => "value 1",
    ],

    "language_code_2"=>[
        "attribute_1" => "value 3",
    ]
]

```

if we call

```
    $model->deleteTranslatableAttribute("attribute_2", "language_code_2");
```

the result will as below

```
[
    "language_code_1"=>[
        "attribute_1" => "value 1",
        "attribute_2" => "value 2",
    ],

    "language_code_2"=>[
        "attribute_1" => "value 3",
    ]
]

```

#### `deleteTranslatableWithLocale(string $locale ): void`

[](#deletetranslatablewithlocalestring-locale--void)

This will remove all translation with specified locale. if we call

```
    $model->deleteTranslatableWithLocale("language_code_2");
```

the result will as below

```
[
    "language_code_1"=>[
        "attribute_1" => "value 1",
        "attribute_2" => "value 2",
    ]
]

```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/710ed9dde4b8cbcbc613ec7227fdf6c672675c93eb1077847c47b9ee5d006dd2?d=identicon)[Xavier Au](/maintainers/Xavier%20Au)

---

Top Contributors

[![xavierauana](https://avatars.githubusercontent.com/u/11531712?v=4)](https://github.com/xavierauana "xavierauana (9 commits)")

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/anacreation-translatable/health.svg)](https://phpackages.com/packages/anacreation-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)
