1. Go to this page and download the library: Download javaabu/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/ */
javaabu / translatable example snippets
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Javaabu\Translatable\DbTranslatable\DbTranslatableSchema;
return new class extends Migration {
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
// ...
$table->dbTranslatable();
// OR
$table->jsonTranslatable();
});
}
public function down(): void
{
Schema::dropIfExists('posts');
}
};
...
class Post extends Model implements Translatable
{
use IsDbTranslatable;
// OR
use IsJsonTranslatable;
...
app()->setLocale('en');
$post->title // This is an English title
app()->setLocale('dv');
$post->title // Mee dhivehi title eh
$post->title_en // This is an English title
$post->title_dv // Mee dhivehi title eh
// to add title for dv language
$post->title_dv = "Mee Dhivehi title eh";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.