2017 © Pedro Peláez
 

library laravel-translatable

A trait to make an Eloquent model hold translations

image

spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  • Monday, March 12, 2018
  • by Spatie
  • Repository
  • 10 Watchers
  • 527 Stars
  • 199,397 Installations
  • PHP
  • 36 Dependents
  • 0 Suggesters
  • 80 Forks
  • 0 Open issues
  • 20 Versions
  • 22 % Grown

The README.md

A trait to make Eloquent models translatable

Latest Version on Packagist MIT Licensed GitHub Workflow Status Total Downloads, (*1)

This package contains a trait HasTranslations to make Eloquent models translatable. Translations are stored as json. There is no extra table needed to hold them., (*2)

use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;

class NewsItem extends Model
{
    use HasTranslations;

    // ...
}

After the trait is applied on the model you can do these things:, (*3)

$newsItem = new NewsItem;
$newsItem
   ->setTranslation('name', 'en', 'Name in English')
   ->setTranslation('name', 'nl', 'Naam in het Nederlands')
   ->save();

$newsItem->name; // Returns 'Name in English' given that the current app locale is 'en'
$newsItem->getTranslation('name', 'nl'); // returns 'Naam in het Nederlands'

app()->setLocale('nl');

$newsItem->name; // Returns 'Naam in het Nederlands'

// If you want to query records based on locales, you can use the `whereLocale` and `whereLocales` methods.

NewsItem::whereLocale('name', 'en')->get(); // Returns all news items with a name in English

NewsItem::whereLocales('name', ['en', 'nl'])->get(); // Returns all news items with a name in English or Dutch

// Returns all news items that has name in English with value `Name in English` 
NewsItem::query()->whereJsonContainsLocale('name', 'en', 'Name in English')->get();

// Returns all news items that has name in English or Dutch with value `Name in English` 
NewsItem::query()->whereJsonContainsLocales('name', ['en', 'nl'], 'Name in English')->get();

// The last argument is the "operand" which you can tweak to achieve something like this:

// Returns all news items that has name in English with value like `Name in...` 
NewsItem::query()->whereJsonContainsLocale('name', 'en', 'Name in%', 'like')->get();

// Returns all news items that has name in English or Dutch with value like `Name in...` 
NewsItem::query()->whereJsonContainsLocales('name', ['en', 'nl'], 'Name in%', 'like')->get();


Support us

, (*4)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*5)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*6)

Documentation

All documentation is available on our documentation site., (*7)

Testing

composer test

Contributing

Please see CONTRIBUTING for details., (*8)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*9)

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using., (*10)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*11)

We publish all received postcards on our company website., (*12)

Credits

We got the idea to store translations as json in a column from Mohamed Said. Parts of the readme of his multilingual package were used in this readme., (*13)

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

12/03 2018

dev-master

9999999-dev https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

10/03 2018

2.2.0

2.2.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

28/02 2018

2.1.5

2.1.5.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

08/02 2018

2.1.4

2.1.4.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

24/01 2018

2.1.3

2.1.3.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

24/01 2018

dev-analysis-8j9k9B

dev-analysis-8j9k9B https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

24/12 2017

2.1.2

2.1.2.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

20/12 2017

2.1.1

2.1.1.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

21/09 2017

2.1.0

2.1.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

30/08 2017

dev-laravel-55

dev-laravel-55 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

30/08 2017

2.0.0

2.0.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

12/06 2017

1.3.0

1.3.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

28/01 2017

1.2.2

1.2.2.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

23/01 2017

1.2.1

1.2.1.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

23/01 2017

1.2.0

1.2.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

02/10 2016

1.1.2

1.1.2.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

24/08 2016

1.1.1

1.1.1.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

02/05 2016

1.1.0

1.1.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

11/04 2016

1.0.0

1.0.0.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n

08/04 2016

0.0.1

0.0.1.0 https://github.com/spatie/laravel-translatable

A trait to make an Eloquent model hold translations

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

eloquent model multilingual translate spatie laravel-translatable i8n