Downloads
Stars
Version
A helper for Model Translations in Laravel.
Easily add translatable fields to any of your eloquent models.
$ composer require berthott/laravel-translatable
php artisan make:model YourModel -m
translatable
macro to add translatable fields in your migration. Eg.
Schema::create('dummies', function (Blueprint $table) {
$table->bigIncrements('id');
$table->translatable('user_input');
$table->timestamps();
});
Translatable
trait to your newly generated model.translatableFields()
method to return an array with a list of your translatable fields to your model.self::translatableRules
to gather all the rules you need to assure the correct data format, eg.
{
"en": "English String",
"de": "German String",
}
translatableOptionalFields()
method to return an array with the fields as keys and the optional languages as an value as an array.translatable_content
, translatable_translations
and translatable_languages
. The languages table will be filled according to the packages config.To change the default options use
$ php artisan vendor:publish --provider="berthott\Translatable\TranslatableServiceProvider" --tag="config"
namespace
: String or array with one ore multiple namespaces that should be monitored for the configured trait. Defaults to App\Models
.namespace_mode
: Defines the search mode for the namespaces. ClassFinder::STANDARD_MODE
will only find the exact matching namespace, ClassFinder::RECURSIVE_MODE
will find all subnamespaces. Defaults to ClassFinder::STANDARD_MODE
.languages
: Defines the languages used in your application. Defaults to ['en' => 'English']
optional_languages
: Defines the languages that should be treated optional. Defaults to []
default_language
: Defines the language that should be used as default. Defaults to en
Tested with Laravel 10.x.
See License File. Copyright © 2023 Jan Bladt.