Added the ability to dynamically translate on the project website.

This commit is contained in:
2024-04-22 23:52:04 +05:00
parent a648ba3db9
commit 491249c8d8
55 changed files with 867 additions and 119 deletions
+25 -2
View File
@@ -2,7 +2,9 @@
namespace App\Models;
use App\Enums\Lang;
use App\Models\Scopes\SortScope;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -33,6 +35,8 @@ final class ProjectLanguage extends Model
'code',
'is_default',
'sort',
'system_lang',
'iso_code',
];
/**
@@ -43,8 +47,27 @@ final class ProjectLanguage extends Model
protected function casts(): array
{
return [
'is_default' => 'boolean',
'sort' => 'integer',
'is_default' => 'boolean',
'sort' => 'integer',
'system_lang' => Lang::class,
];
}
protected function attributeLang(): Attribute
{
return Attribute::make(
get: function () {
if ($this->iso_code) {
return $this->iso_code;
}
if ($this->system_lang) {
return $this->system_lang->getLocale();
}
return $this->code;
},
)->shouldCache();
}
}
@@ -0,0 +1,26 @@
<?php declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
final class ProjectTranslation extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'project_translations';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'project_id',
'language_id',
'text',
'code',
];
}