PHPackages                             mike-zange/laravel-database-translation - 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. mike-zange/laravel-database-translation

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

mike-zange/laravel-database-translation
=======================================

A Laravel package to load translation strings from database with fallback to file system

1.0.1(8y ago)332MITPHPPHP &gt;=7.0

Since Mar 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/MikeZange/laravel-database-translation)[ Packagist](https://packagist.org/packages/mike-zange/laravel-database-translation)[ RSS](/packages/mike-zange-laravel-database-translation/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (2)Versions (8)Used By (0)

[![StyleCI](https://camo.githubusercontent.com/16a4830b876720ba5df3f7a797bfe0647a2e2467fbc3aa1bc93339e3dfc7307a/68747470733a2f2f7374796c6563692e696f2f7265706f732f38353735313932302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/85751920)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/047ae667903ed1771767ddccf2a8b3d3374c623462a32eceaf3f3f34ff0f0990/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d696b655a616e67652f6c61726176656c2d64617461626173652d7472616e736c6174696f6e732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MikeZange/laravel-database-translations/?branch=master)[![Build Status](https://camo.githubusercontent.com/7099c68ac5158a4fe85ae41991f9ff6066f83cd3a0481a18f16901c21cdf0803/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4d696b655a616e67652f6c61726176656c2d64617461626173652d7472616e736c6174696f6e732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/MikeZange/laravel-database-translations/build-status/master)

\#Laravel Database Translations

For Laravel &lt;= 5.4 use version 0.2.x

For Laravel &gt;= 5.5 use version 1.x

Description
-----------

[](#description)

This package extends the functionality of [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable)and will allow you to manage your translation strings in the database while using the file based translations as a fallback.

The fallback priority is as follows:

Database current locale -&gt; Database fallback locale -&gt; File system current locale -&gt; File system fallback locale

This is intentional as this package is meant to be a replacement for the file based language strings

Usage
-----

[](#usage)

You can use the Laravel `trans('group.key')` or `__('group.key')` helpers to display your translations.

The blade `@lang('key')` directive also behaves the same way.

Namespacing works the same as before too

In a Service Provider `app('translator')->addNamespace('namespace', 'path/to/namespaced/folder/lang');`

and `trans('namespace::group.key')`, `__('namepace::group.key')` or `@lang('namepace::group.key')` to display

By default the translations are cached for 1 day with the key `{$locale}.{$namespace}.{$group}`, caching can be disabled in the config file.

The cache for a translation group is refreshed when one of the lines is updated via the translation repository.

### Importing translation files

[](#importing-translation-files)

To load your current translation files in to the database run `php artisan trans-db:load {locale}` where `{locale}`is a language code

For example `php artisan trans-db:load en` will load all the files for 'en' and `php artisan trans-db:load es` will load all the files for 'es'

*Note: this is a catch all function and will include any files in language namespaces you have added to your service providers as well as any in `resources/lang`*

#### Adding more translation keys

[](#adding-more-translation-keys)

The included utility command `php artisan trans-db:load` is non-destructive so add your new key to the appropriate translation file and run the command again, your new key will appear in the database whilst preserving your modified translations

#### Working with translations

[](#working-with-translations)

Add: `use MikeZange\LaravelDatabaseTranslation\Repositories\TranslationRepository;` and inject it into your `__construct()` or method.

1. To retrieve all of the translations from the database: `$translationRepository->all($related = [], $perPage)`
2. Get a group of keys by namespace and group: `$translationRepository->getItems($namespace, $group)`
3. Get a specific key `$translationRepository->getItem($namespace, $group, $key)`

There are 2 included methods for updating translations via the translations repository.

1. `$translationRepository->updateTranslationById($id, $locale, $value, $overwrite)`
2. `$translationRepository->updateTranslation(Translation $line, $locale, $value, $overwrite)`

The second method requires an instance of the translation model.

The optional 4th parameter controls whether the new translation will overwrite the old one if it exists, default is `true`

Requirements
------------

[](#requirements)

- `PHP >=7.0`
- `Laravel ~5.5`
- `spatie/laravel-translatable ^2.1`

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

[](#installation)

1. As always: back up your database - I am not responsible for any data loss
2. Install the package via Composer:

    `composer require mike-zange/laravel-database-translation`
3. **Comment** the following Service Provider in `config/app.php`:

    `Illuminate\Translation\TranslationServiceProvider::class,`

    The new service provider is auto-loaded in laravel 5.5
4. Publish the configuration file `database.translations.php`

    `php artisan vendor:publish --provider="MikeZange\LaravelDatabaseTranslation\TranslationServiceProvider"`
5. Make sure you have a locale set either via `app()->setLocale()` or in `config/app.php`
6. Edit the config at `config/database.translations.php` to your requirements, the defaults should be okay for most uses
7. Run `php artisan migrate` to create the database table

To Do
-----

[](#to-do)

- Allow configuration of caching time

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~78 days

Total

6

Last Release

3073d ago

Major Versions

0.2.2 → 1.0.02018-01-30

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5443707?v=4)[Mike Zange](/maintainers/MikeZange)[@mikezange](https://github.com/mikezange)

---

Top Contributors

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

---

Tags

laravellanguagedatabasetranslation

### Embed Badge

![Health badge](/badges/mike-zange-laravel-database-translation/health.svg)

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

###  Alternatives

[astrotomic/laravel-translatable

A Laravel package for multilingual models

1.4k8.0M135](/packages/astrotomic-laravel-translatable)[codezero/laravel-unique-translation

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

1871.0M8](/packages/codezero-laravel-unique-translation)

PHPackages © 2026

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