PHPackages                             bernardomacedo/laravel-db-translator - 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. bernardomacedo/laravel-db-translator

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

bernardomacedo/laravel-db-translator
====================================

Laravel 5.6 database translation extension

5.6.1(8y ago)482MITPHP

Since Dec 23Pushed 8y ago1 watchersCompare

[ Source](https://github.com/bernardomacedo/laravel-db-translator)[ Packagist](https://packagist.org/packages/bernardomacedo/laravel-db-translator)[ Docs](https://github.com/bernardomacedo/laravel-db-translator)[ RSS](/packages/bernardomacedo-laravel-db-translator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (10)Versions (69)Used By (0)

Laravel Database Translator
===========================

[](#laravel-database-translator)

[![Total Downloads](https://camo.githubusercontent.com/2895067a2c102da4719044a81f0c616a1736b708b8e559b85e77767df179323b/68747470733a2f2f706f7365722e707567782e6f72672f6265726e6172646f6d616365646f2f6c61726176656c2d64622d7472616e736c61746f722f642f746f74616c2e737667)](https://packagist.org/packages/bernardomacedo/laravel-db-translator)[![Latest Stable Version](https://camo.githubusercontent.com/4fe2dfd5ddaae5fbb20dade39eb25273eb027a0a7cf70aa50a868e67cad81bf1/68747470733a2f2f706f7365722e707567782e6f72672f6265726e6172646f6d616365646f2f6c61726176656c2d64622d7472616e736c61746f722f762f737461626c652e737667)](https://packagist.org/packages/bernardomacedo/laravel-db-translator)[![Latest Unstable Version](https://camo.githubusercontent.com/253da72f90ff27298346954d3652822b1b69362f2ee43dfe375e021805640533/68747470733a2f2f706f7365722e707567782e6f72672f6265726e6172646f6d616365646f2f6c61726176656c2d64622d7472616e736c61746f722f762f756e737461626c652e737667)](https://packagist.org/packages/bernardomacedo/laravel-db-translator)[![License](https://camo.githubusercontent.com/202235e6bc798731c945fb2149397955a0cf62d5bc395e51cc7c69c9f8e4b6b5/68747470733a2f2f706f7365722e707567782e6f72672f6265726e6172646f6d616365646f2f6c61726176656c2d64622d7472616e736c61746f722f6c6963656e73652e737667)](https://packagist.org/packages/bernardomacedo/laravel-db-translator)[![Build Status](https://camo.githubusercontent.com/1d3bcba8e3242abb431069b168ce091b9508385d8d7f93caa6b8cdd0a44ed7c4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6265726e6172646f6d616365646f2f6c61726176656c2d64622d7472616e736c61746f722e737667)](https://packagist.org/packages/bernardomacedo/laravel-db-translator)

This package allows you to add translations to database and generates the localization folders per group.

Note:

- It does not replace the current Laravel translator by using another function call to build key/value translations.
- It does not conflict with your current Laravel project.
- It does not replace any of your current translations and works seamlessly with your language files, because this package generates it's own language files and directories.
- Dev Laravel 5.6

Compatibility
-------------

[](#compatibility)

Laravel Framework 5.6

Install
-------

[](#install)

```
$ composer require bernardomacedo/laravel-db-translator
```

First register the service provider and facade in your application.

```
// config/app.php

'providers' => [
    ...
    bernardomacedo\DBTranslator\DBTranslatorServiceProvider::class,
];
'aliases' => [
    ...
    'DBTranslator' => bernardomacedo\DBTranslator\DBTranslatorFacade::class,
];
```

To publish all settings...

```
php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider"
```

...or individually:

```
$ php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider" --tag="config"
```

```
$ php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider" --tag="migrations"
```

```
$ php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider" --tag="lang"
```

And run migrations

```
$ php artisan migrate
```

Add a disk to the `filesystems.php` filestorage:

If you change the default disk name, because it might conflict with another package or with a potential future one, be sure to change it under the published db-translator.php =&gt; storage\_driver` parameter.

```
    'disks' => [
        ...
        'translator' => [
            'driver'    => 'local',
            'root'      => base_path('resources/lang/vendor/dbtranslator')
        ],
        ...

```

Usage
-----

[](#usage)

Default language set to `App::getLocale()`.

In a blade template use:

```
function lang($text = false, $vars = null, $value = null, $group = null, $locale = null)
```

```
{{ lang('some text to translate') }}
{{ lang(':count apple named :name|:count apples named :name', ['name' => 'Bernardo'], 2) }}
{{ lang('{0} There are no apples (:count) named :name|[1,19] There are some (:count) apples named :name|[20,Inf] There are many (:count) apples named :name', ['name' => 'Bernardo'], 2) }}
```

This translation method is easier to interpret because even if the translation is not found, the text you input will be returned.

```
{{ lang('some text to translate') }} // returns 'algum texto para traduzir'
{{ lang('some text to translate', null, null, null, 'ru') }} // returns 'какой-нибудь текст' bypassing the current language forcing a locale.
{{ lang('this text does not exists on the database') }} // returns 'this text does not exists on the database' and will be added for future translation
```

What groups are for?
--------------------

[](#what-groups-are-for)

Sometimes you need to generate a specific translation for a context based situation. Where the same phrase or text you wish to translate, means something different in other languages. So, the group parameter allows you to differentiate the same translation to be translated differently depending on context.

```
{{ lang('participations') }}                /* general group assumed */
{{ lang('participations', null, null, 'some_group') }}  /* some_group group assumed */
```

### Dynamic groups and variables

[](#dynamic-groups-and-variables)

When using dynamic variables for translation, be sure to force a group named 'dynamic\_...'

```
{{ lang($language_name, null, null, 'dynamic_language') }} /* language group assumed with dynamic flag on database */
{{ lang($SomeDynamicVar, null, null, 'dynamic_some_group') }}      /* some_group group assumed with dynamic flag on database */
```

Translating a text
------------------

[](#translating-a-text)

```
DBTranslator::doTranslation($variable_id, $text, $language_id, $group = 'general');
```

DBTranslator will try to find the `$variable_id` and the `$language_id` for you if you only supply strings.

```
DBTranslator::doTranslation('This is cool', 'Isto é cool', 'pt');
```

Sometimes you wish to create a variable for translating, adding a translation directly on a language you choose. So, supplying a string on $variable\_id that does not exist on the `translations_variables` table, will generate a new one, adding an entry to the `translations_translated` table directly.

Generating the translation files
--------------------------------

[](#generating-the-translation-files)

on a controller class

```
use bernardomacedo\DBTranslator\DBTranslator;

class SomeControllerName extends BaseController
{
    public function generate_translations()
    {
        /**
         * This will generate the language translations for all
         * translated texts in the database, and will assume
         * the original language by default.
         * This will work on all languages active by default.
         */
        DBTranslator::generate(); /* will generate all translations */

        DBTranslator::generate('pt'); /* will generate the Portuguese translations */
        DBTranslator::generate(64); /* will generate the Portuguese translations based on ID */
        /**
         * Redirect or do whatever you wish after generation
         */
        return redirect()->route('home');
    }
}
```

This will create all required files under the directory supplied on the `filesystems.php` file.

```
resources/lang/vendor/dbtranslator/
    - en
        - general.php
        - some_group.php
    - pt
        - general.php
        - some_group.php

```

Getting all variables on database
---------------------------------

[](#getting-all-variables-on-database)

```
use bernardomacedo\DBTranslator\Models\Intl;

class SomeControllerName extends BaseController
{
    public function some_function()
    {
        $all = Intl::all();
        $group = Intl::group('general')->get();
    }
}
```

Getting available translations
------------------------------

[](#getting-available-translations)

```
use bernardomacedo\DBTranslator\Models\Translated;

class SomeControllerName extends BaseController
{
    public function some_function()
    {
        /**
         * Gets all available translations
         */
        $all = Translated::all();

        /**
         * Gets all available translations
         */
         $portuguese = Translated::language('pt')->get(); // using string ISO
         $portuguese = Translated::language(64)->get(); // using ID for the language
    }
}
```

Inserting / Removing translations into/from database without rendering views in the browser
-------------------------------------------------------------------------------------------

[](#inserting--removing-translations-intofrom-database-without-rendering-views-in-the-browser)

You can add translations to database without rendering a view. For this you can run a artisan command and `Laravel Database Translator` will check your view folders configured under `config/view.php` config file `paths` and will add any element of lang(\*) found to the database.

### Inserting translations

[](#inserting-translations)

```
$ php artisan dbtranslator:add
```

### Removing unused translations

[](#removing-unused-translations)

```
$ php artisan dbtranslator:remove
```

When running these commands, `Dynamic groups` and `$variables will be ignored. eg:

```
lang($php_var) /* is not supported so they will be ignored */
```

Generating translations
-----------------------

[](#generating-translations)

Generates for Portuguese

```
$ php artisan dbtranslator:generate pt
```

Generates for Spanish

```
$ php artisan dbtranslator:generate es
```

Generates all languages

```
$ php artisan dbtranslator:generate --status=all
```

Generates active languages

```
$ php artisan dbtranslator:generate --status=active
```

Generates inactive languages

```
$ php artisan dbtranslator:generate --status=inactive
```

License
-------

[](#license)

The Laravel Database Translator is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity78

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

Recently: every ~203 days

Total

66

Last Release

2946d ago

Major Versions

2.4 → 5.62018-04-17

### Community

Maintainers

![](https://www.gravatar.com/avatar/5aff79e37a2838988c6f4510557c325b45c5cf863d26f6a4427c00a930bc0fbf?d=identicon)[bernardomacedo](/maintainers/bernardomacedo)

---

Top Contributors

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

---

Tags

laraveltranslationbernardomacedolaravel-db-translator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bernardomacedo-laravel-db-translator/health.svg)

```
[![Health](https://phpackages.com/badges/bernardomacedo-laravel-db-translator/health.svg)](https://phpackages.com/packages/bernardomacedo-laravel-db-translator)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[mariuzzo/laravel-js-localization

Laravel Localization in JavaScript

6073.9M3](/packages/mariuzzo-laravel-js-localization)[kkomelin/laravel-translatable-string-exporter

Translatable String Exporter for Laravel

3291.4M10](/packages/kkomelin-laravel-translatable-string-exporter)

PHPackages © 2026

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