2026-08-06 12:06:55 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Modules\Core\Localization\Filament\Resources;
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
use Filament\Schemas\Schema;
|
|
|
|
|
use Filament\Forms\Components\TextInput;
|
|
|
|
|
use Filament\Schemas\Components\Fieldset;
|
|
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
|
|
|
use Modules\Core\Localization\Filament\Resources\LanguageLineResource\Pages\ListLanguageLines;
|
|
|
|
|
use Modules\Core\Localization\Filament\Resources\LanguageLineResource\Pages\CreateLanguageLine;
|
|
|
|
|
use Modules\Core\Localization\Filament\Resources\LanguageLineResource\Pages\EditLanguageLine;
|
|
|
|
|
use Filament\Forms\Components\Textarea;
|
|
|
|
|
use Illuminate\Support\Collection;
|
2026-08-06 12:06:55 +03:00
|
|
|
use Filament\Forms;
|
|
|
|
|
use Filament\Resources\Resource;
|
|
|
|
|
use Filament\Tables;
|
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
use Lunar\Models\Language;
|
|
|
|
|
use Modules\Core\Localization\Filament\Resources\LanguageLineResource\Pages;
|
|
|
|
|
use Spatie\TranslationLoader\LanguageLine;
|
|
|
|
|
|
|
|
|
|
class LanguageLineResource extends Resource
|
|
|
|
|
{
|
|
|
|
|
protected static ?string $model = LanguageLine::class;
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
protected static string | \BackedEnum | null $navigationIcon = 'heroicon-o-language';
|
2026-08-06 12:06:55 +03:00
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
protected static string | \UnitEnum | null $navigationGroup = 'Settings';
|
2026-08-06 12:06:55 +03:00
|
|
|
|
|
|
|
|
protected static ?string $modelLabel = 'Translation';
|
|
|
|
|
|
|
|
|
|
protected static ?string $pluralModelLabel = 'Translations';
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
public static function form(Schema $schema): Schema
|
2026-08-06 12:06:55 +03:00
|
|
|
{
|
2026-08-31 13:16:13 +03:00
|
|
|
return $schema->components([
|
|
|
|
|
TextInput::make('group')
|
2026-08-06 12:06:55 +03:00
|
|
|
->required()
|
|
|
|
|
->maxLength(255)
|
|
|
|
|
->default('storefront')
|
|
|
|
|
->helperText('Namespace for this label, e.g. "storefront" for e-shop UI text.'),
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
TextInput::make('key')
|
2026-08-06 12:06:55 +03:00
|
|
|
->required()
|
|
|
|
|
->maxLength(255)
|
|
|
|
|
->helperText('Dot-notation key, e.g. "nav.cart".'),
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
Fieldset::make('Translations')
|
2026-08-06 12:06:55 +03:00
|
|
|
->schema(static::localeInputs()),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function table(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
|
|
|
|
->columns([
|
2026-08-31 13:16:13 +03:00
|
|
|
TextColumn::make('group')
|
2026-08-06 12:06:55 +03:00
|
|
|
->badge()
|
|
|
|
|
->sortable(),
|
2026-08-31 13:16:13 +03:00
|
|
|
TextColumn::make('key')
|
2026-08-06 12:06:55 +03:00
|
|
|
->searchable()
|
|
|
|
|
->sortable(),
|
|
|
|
|
...static::localeColumns(),
|
|
|
|
|
])
|
|
|
|
|
->filters([
|
2026-08-31 13:16:13 +03:00
|
|
|
SelectFilter::make('group')
|
2026-08-06 12:06:55 +03:00
|
|
|
->options(fn () => LanguageLine::query()->distinct()->pluck('group', 'group')),
|
|
|
|
|
])
|
|
|
|
|
->defaultSort('key');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getRelations(): array
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getPages(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-08-31 13:16:13 +03:00
|
|
|
'index' => ListLanguageLines::route('/'),
|
|
|
|
|
'create' => CreateLanguageLine::route('/create'),
|
|
|
|
|
'edit' => EditLanguageLine::route('/{record}/edit'),
|
2026-08-06 12:06:55 +03:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-08-31 13:16:13 +03:00
|
|
|
* @return array<Textarea>
|
2026-08-06 12:06:55 +03:00
|
|
|
*/
|
|
|
|
|
private static function localeInputs(): array
|
|
|
|
|
{
|
|
|
|
|
return static::localeCodes()
|
2026-08-31 13:16:13 +03:00
|
|
|
->map(fn (string $code) => Textarea::make("text.{$code}")
|
2026-08-06 12:06:55 +03:00
|
|
|
->label(strtoupper($code))
|
|
|
|
|
->rows(2))
|
|
|
|
|
->all();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-08-31 13:16:13 +03:00
|
|
|
* @return array<TextColumn>
|
2026-08-06 12:06:55 +03:00
|
|
|
*/
|
|
|
|
|
private static function localeColumns(): array
|
|
|
|
|
{
|
|
|
|
|
return static::localeCodes()
|
2026-08-31 13:16:13 +03:00
|
|
|
->map(fn (string $code) => TextColumn::make("text.{$code}")
|
2026-08-06 12:06:55 +03:00
|
|
|
->label(strtoupper($code))
|
|
|
|
|
->limit(40)
|
|
|
|
|
->toggleable())
|
|
|
|
|
->all();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-31 13:16:13 +03:00
|
|
|
private static function localeCodes(): Collection
|
2026-08-06 12:06:55 +03:00
|
|
|
{
|
|
|
|
|
return Language::query()->pluck('code');
|
|
|
|
|
}
|
|
|
|
|
}
|