PHPackages                             spatie/laravel-translation-loader - 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. [Database &amp; ORM](/categories/database)
4. /
5. spatie/laravel-translation-loader

ActiveLibrary[Database &amp; ORM](/categories/database)

spatie/laravel-translation-loader
=================================

Store your language lines in the database, yaml or other sources

2.8.3(2mo ago)8362.9M—2%9020MITPHPPHP ^8.0CI passing

Since Oct 5Pushed 2mo ago12 watchersCompare

[ Source](https://github.com/spatie/laravel-translation-loader)[ Packagist](https://packagist.org/packages/spatie/laravel-translation-loader)[ Docs](https://github.com/spatie/laravel-translation-loader)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-translation-loader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (41)Used By (20)

Store your language lines in the database
=========================================

[](#store-your-language-lines-in-the-database)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0525c630a6d018d2725b8b3fd76962bb313d4c07927ab68e8dd923818815bfe4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d7472616e736c6174696f6e2d6c6f616465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-translation-loader)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/9f7420308977c65ed9154497e8ca039a112035f65fc0ca148fa74308eed448f7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d7472616e736c6174696f6e2d6c6f616465722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473267374796c653d666c61742d737175617265)](https://github.com/spatie/laravel-translation-loader/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/2e06b63965ff3a504cc23583d7ce7b23e75be2413bf9e20edfc531aa1b661671/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d7472616e736c6174696f6e2d6c6f616465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-translation-loader)

In a vanilla Laravel or Lumen installation, you can use [language files](https://laravel.com/docs/localization) to localize your app. This package will enable the translations to be stored in the database. You can still use all the features of [the `__` helper function](https://laravel.com/docs/localization#retrieving-translation-strings) you know and love.

```
__('messages.welcome', ['name' => 'dayle']);
```

You can even mix using language files and the database. If a translation is present in both a file and the database, the database version will be returned.

Want to use a different source for your translations? No problem! The package is [easily extendable](https://github.com/spatie/laravel-translation-loader#creating-your-own-translation-providers).

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/d4a710fef761fd7be0e0460a243b2c217e7e182457c50025937ad0b9186fc974/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7472616e736c6174696f6e2d6c6f616465722e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-translation-loader)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-translation-loader
```

In `config/app.php` (Laravel) or `bootstrap/app.php` (Lumen) you should replace Laravel's translation service provider

```
Illuminate\Translation\TranslationServiceProvider::class,
```

by the one included in this package:

```
Spatie\TranslationLoader\TranslationServiceProvider::class,
```

You must publish and run the migrations to create the `language_lines` table:

```
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-migrations"
php artisan migrate
```

Optionally, you could publish the config file using this command.

```
php artisan vendor:publish --provider="Spatie\TranslationLoader\TranslationServiceProvider" --tag="translation-loader-config"
```

This is the contents of the published config file:

```
return [

    /*
     * Language lines will be fetched by these loaders. You can put any class here that implements
     * the Spatie\TranslationLoader\TranslationLoaders\TranslationLoader-interface.
     */
    'translation_loaders' => [
        Spatie\TranslationLoader\TranslationLoaders\Db::class,
    ],

    /*
     * This is the model used by the Db Translation loader. You can put any model here
     * that extends Spatie\TranslationLoader\LanguageLine.
     */
    'model' => Spatie\TranslationLoader\LanguageLine::class,

    /*
     * This is the translation manager that overrides the default Laravel `translation.loader`
     */
    'translation_manager' => Spatie\TranslationLoader\TranslationLoaderManager::class,

];
```

> **Note:** publishing assets doesn't work out of the box in Lumen. Instead, you have to copy the files from the repo.

Usage
-----

[](#usage)

You can create a translation in the database by creating and saving an instance of the `Spatie\TranslationLoader\LanguageLine`-model:

```
use Spatie\TranslationLoader\LanguageLine;

LanguageLine::create([
   'group' => 'validation',
   'key' => 'required',
   'text' => ['en' => 'This is a required field', 'nl' => 'Dit is een verplicht veld'],
]);
```

You can fetch the translation with [Laravel's default `__` function](https://laravel.com/docs/localization#retrieving-translation-strings):

```
__('validation.required'); // returns 'This is a required field'

app()->setLocale('nl');

__('validation.required'); // returns 'Dit is een verplicht veld'
```

You can still keep using the default language files as well. If a requested translation is present in both the database and the language files, the database version will be returned.

If you need to store/override JSON translation lines, just create a normal LanguageLine with `group => '*'`.

Creating your own translation providers
---------------------------------------

[](#creating-your-own-translation-providers)

This package ships with a translation provider that can fetch translations from the database. If you're storing your translations in a yaml-file, a csv-file, etc., you can easily extend this package by creating your own translation provider.

A translation provider can be any class that implements the `Spatie\TranslationLoader\TranslationLoaders\TranslationLoader`-interface. It contains only one method:

```
namespace Spatie\TranslationLoader\TranslationLoaders;

interface TranslationLoader
{
    /*
     * Returns all translations for the given locale and group.
     */
    public function loadTranslations(string $locale, string $group): array;
}
```

Translation providers can be registered in the `translation_loaders` key of the config file.

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security, please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity66

Solid adoption and visibility

Community44

Growing community involvement

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 60.6% 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 ~90 days

Recently: every ~277 days

Total

39

Last Release

86d ago

Major Versions

0.0.1 → 1.0.02016-10-07

1.2.1 → 2.0.02017-08-31

PHP version history (5 changes)0.0.1PHP ^7.0

2.1.5PHP ^7.1

2.6.0PHP ^7.2

2.7.0PHP ^7.2|^8.0

2.8.2PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (97 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (19 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (3 commits)")[![erikn69](https://avatars.githubusercontent.com/u/4933954?v=4)](https://github.com/erikn69 "erikn69 (2 commits)")[![skalero01](https://avatars.githubusercontent.com/u/2976641?v=4)](https://github.com/skalero01 "skalero01 (2 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (2 commits)")[![aginev](https://avatars.githubusercontent.com/u/8341783?v=4)](https://github.com/aginev "aginev (2 commits)")[![bmichotte](https://avatars.githubusercontent.com/u/235510?v=4)](https://github.com/bmichotte "bmichotte (2 commits)")[![haringsrob](https://avatars.githubusercontent.com/u/866743?v=4)](https://github.com/haringsrob "haringsrob (1 commits)")[![jorenvh](https://avatars.githubusercontent.com/u/8791625?v=4)](https://github.com/jorenvh "jorenvh (1 commits)")[![l3aro](https://avatars.githubusercontent.com/u/25253808?v=4)](https://github.com/l3aro "l3aro (1 commits)")[![Lloople](https://avatars.githubusercontent.com/u/5665466?v=4)](https://github.com/Lloople "Lloople (1 commits)")[![mojtabaahn](https://avatars.githubusercontent.com/u/9845317?v=4)](https://github.com/mojtabaahn "mojtabaahn (1 commits)")[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (1 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (1 commits)")[![Rattone](https://avatars.githubusercontent.com/u/7362607?v=4)](https://github.com/Rattone "Rattone (1 commits)")[![sashaphmn](https://avatars.githubusercontent.com/u/122053040?v=4)](https://github.com/sashaphmn "sashaphmn (1 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (1 commits)")

---

Tags

i18nlanguagelaravelphptranslationspatielaravellanguagetranslatedatabasei8ndblaravel-translation-loader

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/spatie-laravel-translation-loader/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-translation-loader/health.svg)](https://phpackages.com/packages/spatie-laravel-translation-loader)
```

###  Alternatives

[tomatophp/filament-translations

Manage your translation with DB and cache, you can scan your languages tags like trans(), \_\_(), and get the string inside and translate them use UI.

6230.1k3](/packages/tomatophp-filament-translations)[spatie/laravel-translatable

A trait to make an Eloquent model hold translations

2.4k23.0M413](/packages/spatie-laravel-translatable)[spatie/laravel-model-flags

Add flags to Eloquent models

4301.1M1](/packages/spatie-laravel-model-flags)[codezero/laravel-unique-translation

Check if a translated value in a JSON column is unique in the database.

186965.1k7](/packages/codezero-laravel-unique-translation)[cybercog/laravel-clickhouse

ClickHouse migrations for Laravel

163166.8k](/packages/cybercog-laravel-clickhouse)[webparking/laravel-db-rebuild

A laravel package that allows for quick database rebuilds with presets.

448.8k](/packages/webparking-laravel-db-rebuild)

PHPackages © 2026

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