PHP code example of internetguru / laravel-translatable
1. Go to this page and download the library: Download internetguru/laravel-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/ */
internetguru / laravel-translatable example snippets
use InternetGuru\Translatable\Translatable;
class Room extends Model
{
use Translatable;
}
protected $translatable = ['name'];
app()->setLocale('en');
app()->setFallbackLocale('en');
$room = new Room();
$room->save();
// No translation set
echo $room->name; // null
$room->name = 'Living Room';
echo $room->name; // Living Room
app()->setLocale('cs');
$room->name = 'Obývací pokoj';
echo $room->name; // Obývací pokoj
app()->setLocale('en');
echo $room->name; // Living Room
app()->setLocale('cs');
echo $room->name; // Obývací pokoj
// Fallback to the fallback locale
app()->setLocale('de');
echo $room->name; // Living Room
// Fallback to the first translation if fallback locale not found
app()->setFallbackLocale('fr');
echo $room->name; // Living Room