Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features: Add Arabic language + Add Support Spatie translatable #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"require": {
"php": "^8.1",
"filament/filament": "^3.0",
"spatie/laravel-package-tools": "^1.15.0"
"filament/spatie-laravel-translatable-plugin": "^3.2",
"spatie/laravel-package-tools": "^1.15.0",
"solution-forest/filament-translate-field": "^1.3.2"
},
"require-dev": {
"laravel/pint": "^1.0",
Expand Down
2 changes: 2 additions & 0 deletions config/filament-menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
'menu_items' => 'menu_items',
'menu_locations' => 'menu_locations',
],
'translation'=>false,
'locales'=>['en'],
];
5 changes: 3 additions & 2 deletions database/migrations/create_menus_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ return new class extends Migration
{
Schema::create(config('filament-menu-builder.tables.menus'), function (Blueprint $table) {
$table->id();
$table->string('name');
config('filament-menu-builder.translation')?
$table->json('name') : $table->string('name');
$table->boolean('is_visible')->default(true);
$table->timestamps();
});
Expand All @@ -23,7 +24,7 @@ return new class extends Migration
$table->foreignIdFor(Menu::class)->constrained()->cascadeOnDelete();
$table->foreignIdFor(MenuItem::class, 'parent_id')->nullable()->constrained($table->getTable())->nullOnDelete();
$table->nullableMorphs('linkable');
$table->string('title');
config('filament-menu-builder.translation')? $table->json('title') : $table->string('title');
$table->string('url')->nullable();
$table->string('target', 10)->default(LinkTarget::Self);
$table->integer('order')->default(0);
Expand Down
87 changes: 87 additions & 0 deletions resources/lang/ar/menu-builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

declare(strict_types=1);

return [
'form' => [
'title' => 'العنوان',
'url' => 'الرابط',
'linkable_type' => 'النوع',
'linkable_id' => 'المعرف',
],
'resource' => [
'name' => [
'label' => 'الاسم',
],
'locations' => [
'label' => 'المواقع',
'empty' => 'غير معين',
],
'items' => [
'label' => 'العناصر',
],
'is_visible' => [
'label' => 'الرؤية',
'visible' => 'مرئي',
'hidden' => 'مخفي',
],
],
'actions' => [
'add' => [
'label' => 'إضافة إلى القائمة',
],
'locations' => [
'label' => 'المواقع',
'heading' => 'إدارة المواقع',
'description' => 'اختر القائمة التي تظهر في كل موقع.',
'submit' => 'تحديث',
'form' => [
'location' => [
'label' => 'الموقع',
],
'menu' => [
'label' => 'القائمة المعينة',
],
],
'empty' => [
'heading' => 'لا توجد مواقع مسجلة',
],
],
],
'items' => [
'expand' => 'توسيع',
'collapse' => 'طي',
'empty' => [
'heading' => 'لا توجد عناصر في هذه القائمة.',
],
],
'custom_link' => 'رابط مخصص',
'custom_text' => 'نص مخصص',
'open_in' => [
'label' => 'فتح في',
'options' => [
'self' => 'نفس علامة التبويب',
'blank' => 'علامة تبويب جديدة',
'parent' => 'علامة التبويب الأصلية',
'top' => 'علامة التبويب العليا',
],
],
'notifications' => [
'created' => [
'title' => 'تم إنشاء الرابط',
],
'locations' => [
'title' => 'تم تحديث مواقع القائمة',
],
],
'panel' => [
'empty' => [
'heading' => 'لم يتم العثور على عناصر',
'description' => 'لا توجد عناصر في هذه القائمة.',
],
'pagination' => [
'previous' => 'السابق',
'next' => 'التالي',
],
],
];
2 changes: 2 additions & 0 deletions resources/views/components/menu-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ class="transition duration-200 ease-in-out"
{{ $item->url }}
</div>
</div>

<div class="flex items-center gap-2">
<x-filament::badge :color="$item->type === 'internal' ? 'primary' : 'gray'" class="hidden sm:block">
{{ $item->type }}
</x-filament::badge>

{{ ($this->editAction)(['id' => $item->getKey(), 'title' => $item->title]) }}
{{ ($this->deleteAction)(['id' => $item->getKey(), 'title' => $item->title]) }}
</div>
Expand Down
17 changes: 12 additions & 5 deletions src/Livewire/CreateCustomLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
use Illuminate\Contracts\View\View;
use Illuminate\Validation\Rule;
use Livewire\Component;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;

class CreateCustomLink extends Component implements HasForms
{
use InteractsWithForms;

public Menu $menu;

public string $title = '';
public array|string $title;

public string $url = '';

Expand All @@ -31,7 +32,7 @@ class CreateCustomLink extends Component implements HasForms
public function save(): void
{
$this->validate([
'title' => ['required', 'string'],
'title' => ['required'],
'url' => ['required', 'string'],
'target' => ['required', 'string', Rule::in(LinkTarget::cases())],
]);
Expand All @@ -56,11 +57,17 @@ public function save(): void

public function form(Form $form): Form
{


return $form
->schema([
TextInput::make('title')
->label(__('filament-menu-builder::menu-builder.form.title'))
->required(),
config('filament-menu-builder.translation')?
Translate::make()
->locales(config('filament-menu-builder.locales'))
->schema([
TextInput::make("title")->required(),
]) : TextInput::make("title")->required()
,
TextInput::make('url')
->label(__('filament-menu-builder::menu-builder.form.url'))
->required(),
Expand Down
14 changes: 11 additions & 3 deletions src/Livewire/MenuItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Livewire\Attributes\Computed;
use Livewire\Attributes\On;
use Livewire\Component;
use SolutionForest\FilamentTranslateField\Forms\Component\Translate;

class MenuItems extends Component implements HasActions, HasForms
{
Expand Down Expand Up @@ -86,9 +87,15 @@ public function editAction(): Action
->first()
->toArray())
->form([
TextInput::make('title')
->label(__('filament-menu-builder::menu-builder.form.title'))
->required(),
config('filament-menu-builder.translation')?
Translate::make()
->locales(config('filament-menu-builder.locales'))
->schema([
TextInput::make("title")
->label(__('filament-menu-builder::menu-builder.form.title'))->required(),
]) : TextInput::make("title")
->label(__('filament-menu-builder::menu-builder.form.title'))->required()
,
TextInput::make('url')
->hidden(fn (?string $state, Get $get): bool => blank($state) || filled($get('linkable_type')))
->label(__('filament-menu-builder::menu-builder.form.url'))
Expand Down Expand Up @@ -118,6 +125,7 @@ public function editAction(): Action
->slideOver();
}


public function deleteAction(): Action
{
return Action::make('delete')
Expand Down
5 changes: 4 additions & 1 deletion src/Models/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use Datlechin\FilamentMenuBuilder\FilamentMenuBuilderPlugin;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Spatie\Translatable\HasTranslations;

/**
* @property int $id
* @property string $name
* @property string|json $name
* @property bool $is_visible
* @property \Illuminate\Support\Carbon $created_at
* @property \Illuminate\Support\Carbon $updated_at
Expand All @@ -21,6 +22,8 @@
*/
class Menu extends Model
{
use HasTranslations;
public $translatable = ['name'];
protected $guarded = [];

public function getTable(): string
Expand Down
3 changes: 3 additions & 0 deletions src/Models/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Spatie\Translatable\HasTranslations;

/**
* @property int $id
Expand All @@ -32,6 +33,8 @@
*/
class MenuItem extends Model
{
use HasTranslations;
public $translatable = ['title'];
protected $guarded = [];

protected $with = ['linkable'];
Expand Down
1 change: 1 addition & 0 deletions src/Models/MenuLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
class MenuLocation extends Model
{

protected $guarded = [];

public function getTable(): string
Expand Down
3 changes: 3 additions & 0 deletions src/Resources/MenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\Str;
use Filament\Resources\Concerns\Translatable;

class MenuResource extends Resource
{

use Translatable;
public static function getModel(): string
{
return FilamentMenuBuilderPlugin::get()->getMenuModel();
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/MenuResource/Pages/EditMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class EditMenu extends EditRecord
{
use HasLocationAction;
use EditRecord\Concerns\Translatable;

protected static string $view = 'filament-menu-builder::edit-record';

Expand All @@ -33,6 +34,7 @@ public function form(Form $form): Form
protected function getHeaderActions(): array
{
return [
Actions\LocaleSwitcher::make(),
Actions\DeleteAction::make(),
$this->getLocationAction(),
];
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/MenuResource/Pages/ListMenus.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class ListMenus extends ListRecords
{
use HasLocationAction;
use ListRecords\Concerns\Translatable;

public static function getResource(): string
{
Expand All @@ -21,6 +22,7 @@ public static function getResource(): string
protected function getHeaderActions(): array
{
return [
Actions\LocaleSwitcher::make(),
Actions\CreateAction::make(),
$this->getLocationAction(),
];
Expand Down