2017 © Pedro Peláez
 

library laravel-db-localization

Database localization package for laravel framework

image

despark/laravel-db-localization

Database localization package for laravel framework

  • Tuesday, May 22, 2018
  • by tbanov
  • Repository
  • 9 Watchers
  • 11 Stars
  • 316 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 19 Versions
  • 1 % Grown

The README.md

Laravel DB Localization for version 5.1

Note: if you are looking for the version for Laravel 4.2 check out v1 branch., (*1)

Installation

Open composer.json file of your project and add the following to the require array:, (*2)

"despark/laravel-db-localization": "2.0.*"

Now run composer update to install the new requirement., (*3)

Once it's installed, you need to register the service provider in config/app.php in the providers array:, (*4)

'providers' => array(
  ...
  Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider::class,
);

Publish config file: php artisan vendor:publish --provider="Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider" --tag="config", (*5)

Publish migrations: php artisan vendor:publish --provider="Despark\LaravelDbLocalization\LaravelDbLocalizationServiceProvider" --tag="migrations", (*6)

How to use it

Database Example

  • First you need to create your languages table
Schema::create('i18n', function (Blueprint $table) {
        $table->increments('id');
        $table->string('locale')->unique()->index();
        $table->string('name')->index();
        $table->timestamps();
});
  • Example of translatable table
Schema::create('contacts', function (Blueprint $table) {
        $table->increments('id');

        // untranslatable columns
        $table->string('fax');
        $table->string('phone');
        $table->timestamps();
});
  • Example of translations table
Schema::create('contacts_i18n', function (Blueprint $table) {

        $table->integer('contact_id')->unsigned();
        $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade');
        $table->integer('i18n_id')->unsigned();
        $table->foreign('i18n_id')->references('id')->on('i18n')->onDelete('cascade');

        // translatable columns
        $table->string('name', 100);
        $table->string('location', 100);

        $table->unique(['contact_id', 'i18n_id']);
        $table->primary(['contact_id', 'i18n_id']);
        $table->timestamps();
});

Model Example


use Despark\LaravelDbLocalization\i18nModelTrait; class Contacts extends Eloquent { use i18nModelTrait; // You must use i18nModelTrait protected $fillable = [ 'fax', 'phone', ]; protected $translator = 'Despark\LaravelDbLocalization\ContactsI18n'; // Here you need to add your translations table model name protected $translatorField = 'contact_id'; // your translator field name protected $localeField = 'i18n_id'; // here is your locale field name protected $translatedAttributes = ['contact_id', 'i18n_id', 'name', 'location']; // translatable fillables } class ContactsI18n extends Eloquent { protected $table = 'contacts_i18n'; }

View example

Create, (*7)

{!! Form::text("fax", null) !!}
{!! Form::text("phone", null) !!}

@foreach($languages as $language)
    {!! Form::text("name[name_$language->id]", null) !!}  // Follow this convention array( fieldname_languageId );
    {!! Form::text("location[location_$language->id]", null) !!}
@endforeach

Retrieve, (*8)

    // locale string
    $contacts->translate('en'); // all fields
    $contacts->translate('en')->location; // specific field

    // locale id
    $i18nId = 2;
    $contacts->translate($i18nId); // all fields
    $contacts->translate($i18nId)->location; // specific field

Config Example

config/laravel-db-localization.php
    'locale_class' => 'Despark\LaravelDbLocalization\I18n', // Eloquent model that handles your languages.

The Versions

22/05 2018

v3.x-dev

3.9999999.9999999.9999999-dev

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anton Geshev
by Tihomir Banov

database laravel framework localization despark

22/05 2018

v3.1

3.1.0.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anton Geshev
by Tihomir Banov

database laravel framework localization despark

21/03 2017

v3.0

3.0.0.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Anton Geshev
by Tihomir Banov

database laravel framework localization despark

16/01 2017

v2.x-dev

2.9999999.9999999.9999999-dev

Database localization package for laravel framework

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Tihomir Banov

database laravel framework localization despark

14/12 2016

v1.x-dev

1.9999999.9999999.9999999-dev

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

13/07 2016

0.0.1

0.0.1.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Tihomir Banov

database laravel framework localization despark

03/11 2015

dev-master

9999999-dev

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

03/11 2015

v2.0.2

2.0.2.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

02/10 2015

v2.0.1

2.0.1.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

02/10 2015

v2.0.0

2.0.0.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

08/07 2015

v1.2.3

1.2.3.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

07/07 2015

v1.2.2

1.2.2.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

04/06 2015

v1.2.1

1.2.1.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

03/06 2015

v1.2.0

1.2.0.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

29/05 2015

v1.1.8

1.1.8.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

28/05 2015

v1.1.7

1.1.7.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

27/05 2015

v1.1.6

1.1.6.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

26/05 2015

v1.1.5

1.1.5.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark

08/05 2015

v1.1.4

1.1.4.0

Database localization package for laravel framework

  Sources   Download

MIT

The Requires

 

by Tihomir Banov

database laravel framework localization despark