1. Go to this page and download the library: Download rainlab/translate-plugin 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/ */
rainlab / translate-plugin example snippets
class User
{
public $implement = [
\RainLab\Translate\Behaviors\TranslatableModel::class
];
public $translatable = ['name'];
}
$user = User::first();
// Outputs the name in the default language
echo $user->name;
$user->translateContext('fr');
// Outputs the name in French
echo $user->name;
$user = User::first();
// Sets the name in the default language
$user->name = 'English';
$user->translateContext('fr');
// Sets the name in French
$user->name = 'Anglais';
// Outputs the name in French
echo $user->lang('fr')->name;
// Gets a single translated attribute for a language
$user->getAttributeTranslated('name', 'fr');
// Sets a single translated attribute for a language
$user->setAttributeTranslated('name', 'Jean-Claude', 'fr');
$user = User::first();
$user->noFallbackLocale()->lang('fr');
// Returns NULL if there is no French translation
$user->name;
public $translatable = [
['title', 'fallback' => false]
];
public $translatable = [
'name',
['slug', 'index' => true]
];
/**
* Post Model for the blog
*/
class Post extends Model
{
// [...]
/**
* @var array implement the TranslatableModel behavior softly.
*/
public $implement = ['@'.\RainLab\Translate\Behaviors\TranslatableModel::class];
/**
* @var array translatable attributes, if available.
*/
public $translatable = ['title'];
// [...]
}