2017 © Pedro Peláez
 

library laravel-db-translator

Laravel 5.6 database translation extension

image

bernardomacedo/laravel-db-translator

Laravel 5.6 database translation extension

  • Wednesday, April 18, 2018
  • by bernardomacedo
  • Repository
  • 1 Watchers
  • 3 Stars
  • 72 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 69 Versions
  • 6 % Grown

The README.md

Laravel Database Translator

Total Downloads Latest Stable Version Latest Unstable Version License Build Status, (*1)

This package allows you to add translations to database and generates the localization folders per group., (*2)

Note:, (*3)

  • 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

Laravel Framework 5.6, (*4)

Install

``` bash $ composer require bernardomacedo/laravel-db-translator, (*5)


First register the service provider and facade in your application. ```php // config/app.php 'providers' => [ ... bernardomacedo\DBTranslator\DBTranslatorServiceProvider::class, ]; 'aliases' => [ ... 'DBTranslator' => bernardomacedo\DBTranslator\DBTranslatorFacade::class, ];

To publish all settings..., (*6)

``` bash php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider", (*7)


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

``` bash $ php artisan vendor:publish --provider="bernardomacedo\DBTranslator\DBTranslatorServiceProvider" --tag="migrations", (*8)

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

And run migrations, (*9)

``` bash $ php artisan migrate, (*10)


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 => storage_driver` parameter.
'disks' => [
    ...
    'translator' => [
        'driver'    => 'local',
        'root'      => base_path('resources/lang/vendor/dbtranslator')
    ],
    ...

## Usage Default language set to `App::getLocale()`. In a blade template use: ```php 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., (*11)

{{ 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?

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., (*12)

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

Dynamic groups and variables

When using dynamic variables for translation, be sure to force a group named 'dynamic_...', (*13)

{{ 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

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., (*14)

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., (*15)

Generating the translation files

on a controller class, (*16)

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., (*17)

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

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

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

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., (*18)

Inserting translations

``` bash $ php artisan dbtranslator:add, (*19)


### Removing unused translations ``` bash $ php artisan dbtranslator:remove

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

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

Generating translations

Generates for Portuguese ``` bash $ php artisan dbtranslator:generate pt, (*21)

Generates for Spanish
``` bash
$ php artisan dbtranslator:generate es

Generates all languages ``` bash $ php artisan dbtranslator:generate --status=all, (*22)

Generates active languages
``` bash
$ php artisan dbtranslator:generate --status=active

Generates inactive languages bash $ php artisan dbtranslator:generate --status=inactive, (*23)

License

The Laravel Database Translator is open-sourced software licensed under the MIT license, (*24)

The Versions

28/12 2015

2.1.9.x-dev

2.1.9.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.8.x-dev

2.1.8.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.8

2.1.8.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.7.x-dev

2.1.7.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.7

2.1.7.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.6.x-dev

2.1.6.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.6

2.1.6.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.5.x-dev

2.1.5.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.5

2.1.5.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

28/12 2015

2.1.4.x-dev

2.1.4.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

24/12 2015

2.1.3.x-dev

2.1.3.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

24/12 2015

2.1.2.x-dev

2.1.2.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.1.1.x-dev

2.1.1.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.1.1

2.1.1.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.1.0.x-dev

2.1.0.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.1.0

2.1.0.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.9.x-dev

2.0.9.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.9

2.0.9.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.8.x-dev

2.0.8.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.8

2.0.8.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.7.x-dev

2.0.7.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.7

2.0.7.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.6.x-dev

2.0.6.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.6

2.0.6.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.5.x-dev

2.0.5.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.5

2.0.5.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.4.x-dev

2.0.4.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.4

2.0.4.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.3.x-dev

2.0.3.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.3

2.0.3.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.2.x-dev

2.0.2.9999999-dev https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.0.2

2.0.2.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator

23/12 2015

2.1.2

2.1.2.0 https://github.com/bernardomacedo/laravel-db-translator

Laravel 5 database translation extension

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Bernardo Sousa de Macedo

laravel translation bernardomacedo laravel-db-translator