2017 © Pedro Peláez
 

library laravel-eloquent-i18n

image

liaosankai/laravel-eloquent-i18n

  • Sunday, July 29, 2018
  • by liaosankai
  • Repository
  • 1 Watchers
  • 0 Stars
  • 33 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Requirements

  • PHP >= 7.0.0
  • Laravel >= 5.5.0

Installation

You can install the package via composer:, (*1)

composer require liaosankai/laravel-eloquent-i18n

Making a model translatable

use Illuminate\Database\Eloquent\Model;
use Liaosankai\LaravelEloquentI18n\Models\TranslationTrait;

class Book extends Model
{
    use TranslationTrait;

    public $i18nable = [
        'title',
        'content',
        'author',
    ];
}

Write translations data

Set raw attribute, (*2)

$book = new Book();
$book->title = 'raw title';

Set single attribute of single locales, (*3)

$book = new Book();
$book->title = 'raw title';
$book->i18n('zh-Hant')->title = '正體中文的標題';
$book->i18n('zh-Hans')->title = '简体中文的标题';
$book->save();

Set multiple locales of single attribute, (*4)

$book = new Book();
$book->title = 'raw title';
$book->title = [
    'zh-Hant' => '正體中文的標題',
    'zh-Hans' => '简体中文的标题',
    'en' => 'english title',
];
$book->save();

Set multiple attribute of multiple locales, (*5)

$book = new Book();
$book->title = 'raw title';
$book->i18n([
    'zh-Hant' => [
        'title' => '正體中文的標題',
        'content' => '正體中文的內容',
    ],
    'zh-Hans' => [
        'title' => '简体中文的标题',
        'content' => '简体中文的內容',
    ],
    'en' => [
        'title' => 'english title',
        'content' => 'english content',
    ],
])->save();

Read translations data

Arrange presence translations data:, (*6)

$book = new Book();
$book->title = 'raw title';
$book->content = 'raw content';
$book->author = 'raw author';
$book->i18n([
    'zh-Hant' => [
        'title' => '正體中文的標題',
        'content' => '正體中文的內容',
    ],
    'zh-Hans' => [
        'title' => '简体中文的标题',
        'content' => '简体中文的內容',
    ],
    'en' => [
        'title' => 'english title',
        'content' => 'english content',
    ],
])->save();

i18n() use all locales array if unassigned any locale, (*7)

App::setLocale('zh-Hant');
$book->i18n()->title;
/* 
  [
     'zh-Hant' => '正體中文的標題',
     'zh-Hans' => '简体中文的标题',
     'en' => 'english title',
  ]
*/

i18n() use assign locale, (*8)

$book->i18n('zh-Hant')->title; // 正體中文的標題
$book->i18n('zh-Hans')->title; // 简体中文的标题
$book->i18n('zh-en')->title; // english title

i18n() use app locale if assign locale not found, (*9)

App::setLocale('zh-Hant');
$book->i18n('ja')->title; // 正體中文的標題

i18n() use raw data if assign locale attribute not found, (*10)

App::setLocale('zh-Hant');
$book->i18n('zh-Hant')->author; // raw author

Use raw data without i18n(), (*11)

$book->title; // raw title
$book->content; // raw content

filter translations data

use model scope where, (*12)

$book->i18nLike([
    'filter' => [
        'title' => 'keywords for title',
        'content' => 'keywords for content'.
    ],
    'locale' => 'zh-Hant',
])->get();

LICENSE

laravel-eloquent-i18n is released under the MIT License, (*13)

The Versions

29/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate

29/07 2018

v1.2.1

1.2.1.0

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate

05/07 2018

v1.2.0

1.2.0.0

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate

04/07 2018

v1.1.1

1.1.1.0

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate

04/07 2018

v1.1.0

1.1.0.0

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate

04/07 2018

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php ^7.1.3

 

The Development Requires

laravel eloquent model i18n translate