PHPackages                             mnaimjons/multi-lang-entities - 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. mnaimjons/multi-lang-entities

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

mnaimjons/multi-lang-entities
=============================

A Laravel package for handling multi-language entities.

v1.0.0(1y ago)04MITPHPPHP &gt;=7.4

Since Oct 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mnaimjons/multi-lang-entities)[ Packagist](https://packagist.org/packages/mnaimjons/multi-lang-entities)[ RSS](/packages/mnaimjons-multi-lang-entities/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

MultiLangEntities Package
=========================

[](#multilangentities-package)

The `mnaimjons/multi-lang-entities` package allows you to easily manage multi-language (localized) entities in Laravel projects. This package provides a flexible way to translate attributes of any Eloquent model in Laravel.

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

[](#installation)

1. Require the package via Composer:

    ```
    composer require mnaimjons/multi-lang-entities
    ```
2. (Optional) Publish the configuration file:

    You can publish the configuration file to customize the default locale and other settings.

    ```
    php artisan vendor:publish --provider="Mnaimjons\MultiLangEntities\MultiLangEntitiesServiceProvider" --tag="config"
    ```

    This will publish the configuration file `config/multi_lang_entities.php` to your Laravel application.

Configuration
-------------

[](#configuration)

Once the configuration file is published, you can customize the following options:

```
return [
    'default_locale' => env('APP_LOCALE', 'en'), // Default locale
    'eager_loading' => false,                    // Whether to use eager loading for translations
];
```

Usage
-----

[](#usage)

To use the package in your Laravel models, you can add the `HasTranslations` trait to any Eloquent model and define which attributes should be translatable.

### Step 1: Add Translatable Attributes

[](#step-1-add-translatable-attributes)

Add the `HasTranslations` trait to your model and define the attributes you want to translate by adding the `$translatable` property.

**Example with Category Model:**

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mnaimjons\MultiLangEntities\Traits\HasTranslations;

class Category extends Model
{
    use HasTranslations;

    protected $fillable = ['slug'];

    // Define the translatable attributes
    protected $translatable = ['name', 'description'];
}
```

### Step 2: Adding Translations

[](#step-2-adding-translations)

You can add or update translations for any of the defined translatable attributes by calling the `setTranslations` method on the model.

**Example:**

```
$category = Category::find(1);

$category->setTranslations([
    'name' => 'Category Name in English',
    'description' => 'Description in English'
], 'en');  // Adding translation for 'en' (English)

$category->setTranslations([
    'name' => 'Category Name in French',
    'description' => 'Description in French'
], 'fr');  // Adding translation for 'fr' (French)
```

### Step 3: Retrieving Translations

[](#step-3-retrieving-translations)

You can retrieve translated attributes using the standard Eloquent model attribute accessors. The package automatically uses the current application locale (`app()->getLocale()`) to return the appropriate translation.

**Example:**

```
$category = Category::find(1);

// Get the translated name and description based on the current locale
echo $category->name;       // Output: Translated 'name' attribute
echo $category->description; // Output: Translated 'description' attribute
```

### Step 4: Changing Locale

[](#step-4-changing-locale)

If you want to retrieve translations in a specific locale other than the current application locale, you can pass the desired locale to the `getTranslatedAttribute` method.

**Example:**

```
$category = Category::find(1);

// Retrieve translations for the 'fr' locale (French)
$nameInFrench = $category->getTranslatedAttribute('name', 'fr');
$descriptionInFrench = $category->getTranslatedAttribute('description', 'fr');
```

### Step 5: Eager or Lazy Loading Translations

[](#step-5-eager-or-lazy-loading-translations)

By default, translations are **lazy-loaded** (loaded on demand). If you want to **eager-load** translations to improve performance, use the `withTranslations` method.

**Example:**

```
$category = Category::find(1)->withTranslations();  // Eager-load translations

echo $category->name;  // Will use eager-loaded translations
```

Artisan Commands
----------------

[](#artisan-commands)

The package provides several Artisan commands to manage translations from the command line:

1. **List Translations**: Display all translations for a specific entity.

    ```
    php artisan translations:list "App\Models\Category" 1
    ```

    This will list all translations for the `Category` model with ID `1`.
2. **Add or Update Translations**: Add or update a translation for a specific attribute.

    ```
    php artisan translations:add "App\Models\Category" 1 en name "New Category Name"
    ```
3. **Remove Translation**: Remove a specific translation.

    ```
    php artisan translations:remove "App\Models\Category" 1 en name
    ```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

583d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/mnaimjons-multi-lang-entities/health.svg)

```
[![Health](https://phpackages.com/badges/mnaimjons-multi-lang-entities/health.svg)](https://phpackages.com/packages/mnaimjons-multi-lang-entities)
```

###  Alternatives

[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[vluzrmos/language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.

109554.8k3](/packages/vluzrmos-language-detector)[opgginc/codezero-laravel-localized-routes

A convenient way to set up, manage and use localized routes in a Laravel app.

2770.1k1](/packages/opgginc-codezero-laravel-localized-routes)[kerigard/laravel-lang-ru

Ru lang for Laravel

2116.8k](/packages/kerigard-laravel-lang-ru)[highsolutions/laravel-translation-manager

Manage Laravel Translations

1518.8k](/packages/highsolutions-laravel-translation-manager)[amendozaaguiar/laraveles-spanish-for-jetstream

Archivos de traducción al español latinoamericano para Laravel con Jetstream (auth, pagination, passwords, validation + todas las cadenas de Jetstream).

1412.1k](/packages/amendozaaguiar-laraveles-spanish-for-jetstream)

PHPackages © 2026

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