dnj/laravel-localization

v1.0.1 2023-10-21 18:20 UTC

This package is auto-updated.

Last update: 2024-10-21 20:36:27 UTC


README

Latest Version on Packagist Total Downloads Software License

This package helps you to manage and present your multi-language Eloquent models easier.

There is core concept: You have a record (like Product) and each record has some localized attribute (like title or descriptions). So you create a Eloquent model for your main entity:

<?php
namespace App\Models;

use dnj\Localization\Contracts\ITranslatableModel;
use dnj\Localization\Eloquent\HasTranslate;

class Product extends Model implements ITranslatableModel
{
	use HasTranslate;

	protected $table = "product";
}

And then create another model for its translates:

<?php
namespace App\Models;

use dnj\Localization\Contracts\ITranslateModel;
use dnj\Localization\Eloquent\IsTranslate;

class ProductTranslate extends Model implements ITranslateModel
{
	use IsTranslate;

	protected $table = "product_translate";
}

ITranslatableModel

This interface prodvide two methods for you which you can retrive translates for a model:

To facilitate things there is a HasTranslate trait that taking care of implementing those methods. On top of that, this trait has some extra methods:

ITranslateModel

This model is much simpler. Just contains some getters.

And also there is IsTranslate trait which implements these methods for you.

Security

If you've found a bug regarding security please mail security@dnj.co.ir instead of using the issue tracker.

License

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