This package allows model translation. It is like Symfony's gedmo translation package. It is very easy to use. You can use it in your models or controllers. Basically, it is a trait that you can use in your models. It will automatically create translation records of the fields you specify in the model. It will show the translation according to the registered locale. When creating or updating it will use the registered locale and will process that record. The main table pairs with "foreign_id" and "model namespace" to the translations table.
You can install the package via composer:
composer require onurkacmaz/laravel-model-translate
php artisan vendor:publish --provider="Onurkacmaz\LaravelModelTranslate\LaravelModelTranslateServiceProvider" --tag=config
php artisan vendor:publish --provider="Onurkacmaz\LaravelModelTranslate\LaravelModelTranslateServiceProvider" --tag=migrations
php artisan migrate
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class Blog extends Model
{
use Translatable;
// You can define which fields will be translated
public function getTranslatable(): array
{
return ['title', 'content'];
}
}
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class TestController extends Controller
{
public function index() {
$translate = new LaravelModelTranslate();
$translate->setColumns(['title', 'content']);
$translate->setModel($blog);
$translate->setLocale('en');
$translate->translate();
// or
$translate = new LaravelModelTranslate($blog, ['title', 'content'], 'en');
$translate->translate();
}
}
use Onurkacmaz\LaravelModelTranslate\Traits\Translatable;
class TestController extends Controller
{
public function index() {
$translate = LaravelModelTranslate::make()
->setModel($account)
->setLocale('en')
->setColumns(['title', 'content'])
->translate();
}
}
composer test
Please see CONTRIBUTING for details.
If you discover any security related issues, please email kacmaz.onur@hotmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.