PHP code example of karnoweb / translation

1. Go to this page and download the library: Download karnoweb/translation 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/ */

    

karnoweb / translation example snippets


use Karnoweb\Translation\Concerns\HasTranslation;

class Brand extends Model
{
    use HasTranslation;

    /** @var list<string> */
    protected array $translatable = ['title', 'description'];
}

$brand->setTranslation('title', 'عنوان فارسی', 'fa');
$brand->setTranslation('title', 'English Title', 'en');

app()->setLocale('fa');
echo $brand->fresh()->title; // عنوان فارسی
bash
composer vendor:publish --tag=translation-config       # اختیاری
php artisan vendor:publish --tag=translation-migrations   # الزامی
php artisan migrate