All Projects → fevrok → Laravel Translatable

fevrok / Laravel Translatable

Licence: mit
It's a Laravel database translations manager

Projects that are alternatives of or similar to Laravel Translatable

Backup
MySQL Database backup package for Laravel
Stars: ✭ 66 (+40.43%)
Mutual labels:  database, laravel, laravel-package
Laravel Scout Postgres
PostgreSQL Full Text Search Engine for Laravel Scout
Stars: ✭ 140 (+197.87%)
Mutual labels:  database, laravel, laravel-package
Laravel Sync Migration
Developer tool helps to sync migrations without refreshing the database
Stars: ✭ 89 (+89.36%)
Mutual labels:  database, laravel, laravel-package
Laravel Auto Translate
Automatically translate your language files using a translator service
Stars: ✭ 153 (+225.53%)
Mutual labels:  laravel, laravel-package, translations
Laravel World
provide countries, states, and cities relations and database.
Stars: ✭ 222 (+372.34%)
Mutual labels:  translation, database, laravel
Lara Lens
Laravel package for display diagnostic (config, database, http connections...)
Stars: ✭ 96 (+104.26%)
Mutual labels:  database, laravel, laravel-package
Laravel Database Logger
Log database query sql in Laravel Application, support Guard,Auth to multiple file record
Stars: ✭ 31 (-34.04%)
Mutual labels:  database, laravel, laravel-package
Laravel Db Profiler
Database Profiler for Laravel Web and Console Applications.
Stars: ✭ 141 (+200%)
Mutual labels:  database, laravel, laravel-package
Laravel Localization Helpers
🎌 Artisan commands to generate and update lang files automatically
Stars: ✭ 190 (+304.26%)
Mutual labels:  translation, laravel, laravel-package
Laravel Translatable
[Deprecated] A Laravel package for multilingual models
Stars: ✭ 1,974 (+4100%)
Mutual labels:  database, laravel, translations
Laravel Translatable
A Laravel package for multilingual models
Stars: ✭ 624 (+1227.66%)
Mutual labels:  translation, database, laravel
tarjama
This package allows you to translate your models fields. `2.0` version will be continued here: https://github.com/fevrok/laravel-translatable
Stars: ✭ 2 (-95.74%)
Mutual labels:  translations, translation, laravel-package
Laravel Options
Global key-value store in the database
Stars: ✭ 626 (+1231.91%)
Mutual labels:  database, laravel, laravel-package
Eloquent Driver
A package that allows you to store Statamic entries in a database.
Stars: ✭ 28 (-40.43%)
Mutual labels:  database, laravel
Doorman
Limit access to your Laravel applications by using invite codes
Stars: ✭ 913 (+1842.55%)
Mutual labels:  laravel, laravel-package
Laravel Settings
Simple Settings package for a laravel application
Stars: ✭ 45 (-4.26%)
Mutual labels:  laravel, laravel-package
Gorose
GoRose(go orm), a mini database ORM for golang, which inspired by the famous php framwork laravle's eloquent. It will be friendly for php developer and python or ruby developer. Currently provides six major database drivers: mysql,sqlite3,postgres,oracle,mssql, Clickhouse.
Stars: ✭ 947 (+1914.89%)
Mutual labels:  database, laravel
Chatify
A Laravel package that allows you to add a complete user messaging system into your new/existing Laravel application.
Stars: ✭ 885 (+1782.98%)
Mutual labels:  laravel, laravel-package
Larawiz
Larawiz is a easy project scaffolder for Laravel
Stars: ✭ 28 (-40.43%)
Mutual labels:  database, laravel
History Tracker
Laravel Model history tracking made easy
Stars: ✭ 46 (-2.13%)
Mutual labels:  laravel, laravel-package

translatable

It's a Laravel model columns translation manager

Current working model

Laravel Translatable current working model

Installation

You can install the package via composer:

composer require fevrok/laravel-translatable

If you have Laravel 5.5 and up The package will automatically register itself.

else you have to add the service provider to app/config/app.php

Fevrok\Translatable\TranslatableServiceProvider::class,

publish config file and migration.

php artisan vendor:publish --provider="Fevrok\Translatable\TranslatableServiceProvider"

This is the contents of the published file:

return [

   /**
    * Default Locale || Root columns locale
    * We will use this locale if config('app.locale') translation not exist
    */
   'locale' => 'en',

];

next migrate translations table

php artisan migrate

Making a model translatable

The required steps to make a model translatable are:

  • Just use the Fevrok\Translatable\Translatable trait.

Here's an example of a prepared model:

use Illuminate\Database\Eloquent\Model;
use Fevrok\Translatable\Translatable;

class Item extends Model
{
    use Translatable;

    /**
      * The attributes that are Translatable.
      *
      * @var array
      */
    protected $translatable = [
        'name', 'color'
    ];
}

Custom translations model

To get started, publish the assets again this will create new migration update table name to your desire.

CustomTranslation.php

class CustomTranslation extends \Fevrok\Translatable\Models\Translation
{
    protected $table = 'custom_translations';
}

Add $translations_model property and give it your custom translations class.

use Illuminate\Database\Eloquent\Model;
use Fevrok\Translatable\Translatable;

class Item extends Model
{
    use Translatable;

    /**
      * The attributes that are Translatable.
      *
      * @var array
      */
    protected $translatable = [
        'name'
    ];
	
    /**
      * The model used to get translatios.
      *
      * @var string
      */
    protected $translations_model = CustomTranslation::class;
}

Available methods

Saving translations

$item = new Item;
$data = array('en' => 'car', 'ar' => 'سيارة');

$item->setTranslations('name', $data); // setTranslations($attribute, array $translations, $save = false)

// or save one translation
$item->setTranslation('name', 'en', 'car', true); // setTranslation($attribute, $locale, $value, $save = false)

// or just do
$item->name = 'car'; // note: this will save automaticaly unless it's the default locale

// This will save if (current locale == default locale OR $save = false)
$item->save();

Get translations

$item = new Item::first();
// get current locale translation
$item->city
OR
$item->getTranslation('city');

// pass translation locales
$item->getTranslation('city', 'ar'); // getTranslation($attribute, $language = null, $fallback = true)
$item->getTranslationsOf('name', ['ar', 'en']); // getTranslationsOf($attribute, array $languages = null, $fallback = true)

Delete translations

$item = new Item::first();
$item->deleteTranslations(['name', 'color'], ['ar', 'en']); // deleteTranslations(array $attributes, $locales = null)

Maintainers

Abdellah Chadidi
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].