PHP code example of mosaiqo / translatable

1. Go to this page and download the library: Download mosaiqo/translatable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mosaiqo / translatable example snippets


 Mosaiqo\Translatable\TranslatableServiceProvider::class,

 namespace App;

use Jenssegers\Mongodb\Model;

class Article extends Model 
{

    use \Mosaiqo\Translatable\Traits\Translatable;

    protected $fillable = ['commentable'];

	/**
	 * This are the attributes you want to have in multiple languages.
	 */
	protected $translatableAttributes = ['title', 'slug'];

	
	/**
	 * This is optional by default it will search for App\ArticleLocale.
	 */ 
	protected $translationModel = 'Mosaiqo\Translatable\Tests\Models\ArticleLocale'; 
	

}

 namespace App;

use Jenssegers\Mongodb\Model;

class ArticleLocale extends Eloquent 
{

    protected $fillable = ['title', 'slug'];

}

$article = Article::create([
	'commentable' => true,
	'published'   => true,
	'en' => [
		'title' => 'My title',
		'body'  => 'This is the text for my new post ...'
	]
]);

$article = Article::create([
	'commentable' => true
]);
	
	
$article->en([
	'title' => 'My title',
	'body'  => 'This is the text for my new post ...'
]);

$article->es([
	'title' => 'Mi titulo',
	'body'  => 'Este es mi texto para mi nuevo post ...'
]);	

$article = Article::first();

echo $article->es()->title; 

echo $article->en()->title; 	

$article_es = $article->es();
$article_en = $article->en();

$article->translate('es')->title;	

$article->translate('de', true)->title;

$article->translateOrDefault('de')->title;

$article->translate('de', 'es')->title;

$article->hasTranslation('fr');
$article->hasTranslation('en');

// or

$article->isTranslated('en');
$article->isTranslated('ca');

$article->translations();
shell
php artisan vendor:publish --provider="Mosaiqo\Translatable\TranslatableServiceProvider" --tag="config"