PHPackages                             sohrab-az/laravel-language - 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. sohrab-az/laravel-language

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

sohrab-az/laravel-language
==========================

A flexible language package for Laravel

1.0.0(2mo ago)031MITPHP

Since May 1Pushed 2mo agoCompare

[ Source](https://github.com/sohrab-az/laravel-language)[ Packagist](https://packagist.org/packages/sohrab-az/laravel-language)[ RSS](/packages/sohrab-az-laravel-language/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (1)

Laravel Language Package
========================

[](#laravel-language-package)

A simple and lightweight language management package for Laravel applications.

This package provides a database-driven approach to manage languages, including default language, active languages, and per-model language assignment.

---

Features
--------

[](#features)

- Store languages in database
- Define default language
- Enable/disable languages
- Assign language to Eloquent models
- Fluent service API for managing languages
- Built-in Eloquent trait for multilingual relations

---

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

[](#installation)

You can install the package via composer:

```
composer require sohrab-az/laravel-language
```

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

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=language-config
```

config/language.php

```
return [

    'default' => 'en',

    'supported' => [
        [
            'code' => 'en',
            'name' => 'English',
            'direction' => 'ltr',
            'active' => true
        ],
        [
            'code' => 'fa',
            'name' => 'Persian',
            'direction' => 'rtl',
            'active' => true
        ],
    ],

];
```

Migration
---------

[](#migration)

Run the migrations:

```
php artisan migrate
```

This will create a `languages` table and seed it based on your configuration.

Database Structure
------------------

[](#database-structure)

The languages table includes:

- `code` (string, unique)
- `name` (string)
- `direction` (enum: ltr, rtl)
- `is_active` (boolean)
- `is_default` (boolean)
- `meta` (json, nullable)

Usage
-----

[](#usage)

### Language Manager

[](#language-manager)

You can inject `LanguageManager` anywhere in your application:

```
use Gitmag\Language\Services\LanguageManager;

class ExampleController
{
    public function __construct(protected LanguageManager $languageManager) {}

    public function index()
    {
        $languages = $this->languageManager->all();
        $active = $this->languageManager->active();
        $default = $this->languageManager->default();

        return $languages;
    }
}
```

Set Default Language
--------------------

[](#set-default-language)

```
$languageManager->setDefault('fa');
```

Activate / Deactivate Language
------------------------------

[](#activate--deactivate-language)

```
$languageManager->activate('en');
$languageManager->deactivate('fa');
```

Working with Eloquent Models
----------------------------

[](#working-with-eloquent-models)

Use the `HasLanguage` trait in your model:

```
use Gitmag\Language\Traits\HasLanguage;

class Post extends Model
{
    use HasLanguage;
}
```

Assign Language to Model
------------------------

[](#assign-language-to-model)

```
$post->setLanguage('en')->save();
```

or:

```
$post->setLanguage($languageModel)->save();
```

Query by Language
-----------------

[](#query-by-language)

```
Post::language('en')->get();
Post::language($languageId)->get();
Post::language($languageModel)->get();
```

Default Language Scope
----------------------

[](#default-language-scope)

```
Post::defaultLanguage()->get();
```

Helpers
-------

[](#helpers)

```
$post->getLanguageCode();

$post->isLanguage('en');
```

Service Provider
----------------

[](#service-provider)

The package automatically registers:

- LanguageManager singleton
- Config file
- Migrations

License
-------

[](#license)

MIT

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance84

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity34

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

84d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/54e2e41c158ddc0f29395d4c4e3b16d2e4ba8e0adcc8eca90f092c58d7fde315?d=identicon)[sohrab-az](/maintainers/sohrab-az)

---

Top Contributors

[![sohrab-az](https://avatars.githubusercontent.com/u/76838208?v=4)](https://github.com/sohrab-az "sohrab-az (4 commits)")

### Embed Badge

![Health badge](/badges/sohrab-az-laravel-language/health.svg)

```
[![Health](https://phpackages.com/badges/sohrab-az-laravel-language/health.svg)](https://phpackages.com/packages/sohrab-az-laravel-language)
```

PHPackages © 2026

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