PHPackages                             bruno-fernandes/laravel-multi-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. bruno-fernandes/laravel-multi-language

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

bruno-fernandes/laravel-multi-language
======================================

Simple approach to models multi-language support.

0.0.4(6y ago)2253MITPHPPHP &gt;=7.1CI failing

Since Sep 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/bruno-fernandes/laravel-multi-language)[ Packagist](https://packagist.org/packages/bruno-fernandes/laravel-multi-language)[ Docs](https://github.com/bruno-fernandes/laravel-multi-language)[ RSS](/packages/bruno-fernandes-laravel-multi-language/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Laravel Multi-language
======================

[](#laravel-multi-language)

**IMPORTANT:** Under active development. Do not use in production, api might change.

[![Latest Version on Packagist](https://camo.githubusercontent.com/2e045d78eedc73bfe5c20fc0b1fe4d7e61589054541e89d0eda60ce31ab1a8fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6272756e6f2d6665726e616e6465732f6c61726176656c2d6d756c74692d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bruno-fernandes/laravel-multi-language)[![CircleCI](https://camo.githubusercontent.com/fd2d9fc58fab01298564392396297686e3c8f3f68d346417be3fcace3ab51cfc/68747470733a2f2f636972636c6563692e636f6d2f67682f6272756e6f2d6665726e616e6465732f6c61726176656c2d6d756c74692d6c616e67756167652e7376673f7374796c653d73766726636972636c652d746f6b656e3d32303465346436666465363262396261333830656634643531336135363865323061636534303930)](https://circleci.com/gh/bruno-fernandes/laravel-multi-language)[![CodeCoverage](https://camo.githubusercontent.com/d4dc4c6641a83717384fe46d285cccf4708e3ccfdee3eee795989dda1e3d346e/68747470733a2f2f636f6465636f762e696f2f67682f6272756e6f2d6665726e616e6465732f6c61726176656c2d6d756c74692d6c616e67756167652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/github/bruno-fernandes/laravel-multi-language?branch=master)[![Quality Score](https://camo.githubusercontent.com/dedb4b44e621092b0986dce5e7a031a1d3278f47c869bf1e4ff0ac4e68ef76b9/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6272756e6f2d6665726e616e6465732f6c61726176656c2d6d756c74692d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bruno-fernandes/laravel-multi-language)[![Total Downloads](https://camo.githubusercontent.com/ba0f04dfad54343d231c91e535ed4d2605fcdac6da2219e65bf77c0d507fa5e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6272756e6f2d6665726e616e6465732f6c61726176656c2d6d756c74692d6c616e67756167652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bruno-fernandes/laravel-multi-language)

Simple approach to eloquent models translation. There are other packages that provide translation functionality, this is a different approach with some trade-offs. Priority is simplicity.

// TODO: add example database schema here.

### Key points:

[](#key-points)

- easy to get up running on existing applications
- all eloquent model fields are translatable
- original can be created in any language
- translations can be copied from original
- translations can be easily associated later on

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

[](#installation)

You can install the package via composer:

```
composer require bruno-fernandes/laravel-multi-language
```

If you want to set custom column names, publish the config file and override the defaults:

```
php artisan vendor:publish --provider="BrunoFernandes\LaravelMultiLanguage\LaravelMultiLanguageServiceProvider"
```

Usage
-----

[](#usage)

```
// Import the Translatable trait into the eloquent model
use BrunoFernandes\LaravelMultiLanguage\Translatable;

class Page extends Model
{
    use Translatable;
}

// Create a migration to add the required columns to the model's table
// Example:
class AddMultilanguageFieldsToPagesTable extends Migration
{
    public function up()
    {
        Schema::table('pages', function (Blueprint $table) {
            // Create columns
            $table->string(config('laravel-multi-language.lang_key'), 6)
                ->default('en')->index()->after('id');
            $table->integer(config('laravel-multi-language.foreign_key'))
                ->unsigned()->nullable()->index()->after('id');

            // Create composite unique index to prevent multiple
            // records using the same lang key
            $table->unique([
                config('laravel-multi-language.foreign_key'),
                config('laravel-multi-language.lang_key')
            ]);
        });

        // TODO: if there are already records on the table, create a migration to update
        // all of them and set the lang and the original_id with the correct values
    }
}

//
// Usage
//
$page = Page::create(['title' => 'English title']);
$englishPage = $page->translateTo('es', ['title' => 'Spanish title']);

$originalPages = Page::onlyOriginals()->get();

// the package will apply the lang scope by default, so only
// the current locale records are returned (it can be disable in the config file)
$currentLocalePages = Page::get();

// if apply lang global scope is disabled you can use the lang scope as follow:
$enPagesWithTranslations = Page::lang('en')->withTranslations()->get();
// NOTE: always use withTranslations() rather than with('translations) as it is more efficient
// using withTranslations() will exlude the current locale from the translations relationship

// if you would like to remove a global scope for a given query,
// you may use the  withoutGlobalScope method as follow:
use BrunoFernandes\LaravelMultiLanguage\Scopes\LangScope;
$allPagesOfAllLocales = Page::withoutGlobalScope(LangScope::class)->get();

// TODO: add usage samples to be added
```

### Known issues

[](#known-issues)

- When used with [Searchable package](https://github.com/nicolaslopezj/searchable) global scopes need to be removed and applied manually after the search method is used.
- when using hasOne relationships, if *foreign\_key* and *local\_key* are not set the LangScope (Global Scope) is applied to the relationship, if the relationship model is not translatable an error is thrown.

```
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'live_players.original_id' in 'where clause' (SQL: select * from `live_players` where `live_players`.`original_id` in (35) and `live_players`.`deleted_at` is null) (View: /home/vagrant/code/resources/frontend/views/index.blade.php)
```

```
// This does not work
class Content extends Model
{
    public function livePlayer()
    {
        return $this->hasOne(LivePlayer::class);
    }
}

// This works
class Content extends Model
{
    public function livePlayer()
    {
        return $this->hasOne(LivePlayer::class, 'id', 'live_player_id');
    }
}
```

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Bruno Fernandes](https://github.com/bruno-fernandes)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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 ~61 days

Total

4

Last Release

2247d ago

PHP version history (2 changes)0.0.1PHP ^7.2

0.0.2PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/be74a7d53a14664d616970a7ef60ad373b7642840be3bb883f1a5537969dcc6b?d=identicon)[bruno-fernandes](/maintainers/bruno-fernandes)

---

Top Contributors

[![bruno-fernandes](https://avatars.githubusercontent.com/u/1558329?v=4)](https://github.com/bruno-fernandes "bruno-fernandes (24 commits)")

---

Tags

laravellaravel-5-packagemultilanguaguelaravel-multi-languagebruno-fernandes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bruno-fernandes-laravel-multi-language/health.svg)

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

###  Alternatives

[vluzrmos/language-detector

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

109554.8k3](/packages/vluzrmos-language-detector)[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)
