2017 © Pedro PelĂĄez
 

library laravel-translations

Package to help you easily translate your laravel models

image

escapework/laravel-translations

Package to help you easily translate your laravel models

  • Wednesday, November 2, 2016
  • by luisdalmolin
  • Repository
  • 4 Watchers
  • 2 Stars
  • 51 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Laravel Translations

StyleCI Status Software License Latest Stable Version Total Downloads, (*1)

Easily translate your laravel models to as many languages you need., (*2)

Installation

Add this line to your composer.json file:, (*3)

    "escapework/laravel-translations": "0.2.*"

And add this service provider to your laravel providers:, (*4)

    EscapeWork\Translations\TranslationServiceProvider::class

And publish the migrations running the following command:, (*5)

$ php artisan vendor:publish --provider="EscapeWork\Translations\TranslationServiceProvider"
$ php artisan migrate

Usage

Creating the locales

First, you need to create the locales that your models will be translated., (*6)

EscapeWork\Translations\Locale::create(['id' => 'pt-br', 'title' => 'PortuguĂȘs (Brasil)']);
EscapeWork\Translations\Locale::create(['id' => 'en',    'title' => 'English']);

Then, you need to import the Translatable in your models., (*7)

use EscapeWork\Translations\Translatable;
...

class Product extends Model
{

    use Translatable;
}

Storing a translation

For storing a translation, you can do the following:, (*8)

// $data can have as many fields you want
$data = [
    'title'       => 'My translated title',
    'description' => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit',
];

$product->storeTranslation((array) $data, 'pt-br');

Here it's an example on how you can use with Laravel $request object., (*9)

$product = Product::find(1);

foreach ((array) $request->translations as $locale => $data) {
    $product->storeTranslation((array) $data, $locale);
}

Deleting translations from a model

$product->deleteTranslations();

Getting a translation

For getting an existing translation, you just need to do this:, (*10)

$product = Product::find(1);
echo $product->translations->_get('title'); // this will get the translation for the current config('app.locale') value

If you need an translation for an specific locale, just pass the locale as the second argument:, (*11)

$product = Product::find(1);
echo $product->translations->_get('title', 'pt-br');

If you don't pass the $locale, the default is gonna be the config('app.locale') value., (*12)

You can also do something like this to make your life easier:, (*13)

class Product extends Model
{
    ...
    public function getTitleAttribute()
    {
        return $this->translations->_get('title');
    }
    ...
}

// then, just call like a simple field
echo $product->title;

Next steps

  • Testing;
  • Make use of MySQL 5.7 JSON types, where a search inside the translations will be available;

License

See the License file., (*14)

The Versions

02/11 2016

dev-master

9999999-dev

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

03/10 2016

0.1.0

0.1.0.0

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

01/06 2016

dev-analysis-XlZggV

dev-analysis-XlZggV

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

28/04 2016

dev-analysis-zD2gRg

dev-analysis-zD2gRg

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

27/04 2016

dev-analysis-8QM61o

dev-analysis-8QM61o

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

21/04 2016

dev-analysis-8QMnop

dev-analysis-8QMnop

Package to help you easily translate your laravel models

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires