Easy translation manipulation of your Eloquent models in Laravel 4.
First, you'll need to add the package to the require attribute of your composer.json file:
{
"require": {
"ink/ink-translatable": "dev-master"
},
}Afterwards, run composer update from your command line.
Then, add 'Ink\InkTranslatable\InkTranslatableServiceProvider', to the list of service providers in app/config/app.php
and add 'Translatable' => 'Ink\InkTranslatable\Facades\Translatable' to the list of class aliases in app/config/app.php.
From the command line again, run php artisan config:publish ink/ink-translatable.
Create app/config/locales.php file in the following content:
return array(
'locales' => array('az', 'ru', 'en'),
'default' => 'az',
);Schema::create('posts', function($table)
{
$table->increments('id')->unsigned();
$table->timestamps();
});
Schema::create('posts_translations', function($table)
{
$table->integer('post_id')->unsigned();
$table->string('title');
$table->string('lang');
});example/app/controllers/PostController.php file contains controller sample
example/app/views/post folder contains sample view files
Edit app/routes.php file and add following content:
Route::resource('posts', 'PostController');
Route::get('/posts/{id}/delete', 'PostController@destroy');Change Eloquent to EloquentTranslatable
Define a public static property $translatable with the definitions (see [#Configuration] below for details):
use Ink\InkTranslatable\Models\EloquentTranslatable;
class Post extends EloquentTranslatable
{
public static $translatable = array(
'table' => 'posts_translations',
'relationship_field' => 'post_id',
'locale_field' => 'lang',
'translatables' => array(
'title' => '',
)
);
}That's it ... your model is now "translatable"!
Configuration was designed to be as flexible as possible. You can set up defaults for all of your EloquentTranslatable models, and then override those settings for individual models.
By default, global configuration can be set in the app/config/packages/ink/ink-translatable/config.php file. If a configuration isn't set, then the package defaults from vendor/ink/ink-translatable/src/config/config.php are used. Here is an example configuration, with all the default settings shown:
return array(
'table' => null,
'relationship_field' => null,
'locale_field' => 'lang',
'translatables' => array(
'title' => '',
)
);Please use Github for bugs, comments, suggestions. Pull requests are preferred!
InkTranslatable was written by Orkhan Maharramli and released under the MIT License. See the LICENSE file for details.
Copyright 2013 Orkhan Maharramli