78ff8d4b43
User screenshots showed the tenant admin panel (Filament) had sidebar
labels stuck in Romanian even when switching to Russian: 'Cereri',
'Calendar vizual', 'Atelierul meu', 'KPI mecanici', 'Fișe lucru',
'Norme-ore', 'Tehnicieni', 'Șabloane servicii', 'Depozite', 'Scaner',
'Depozit', 'VIN-căutare', 'Furnizori', 'Achiziții', 'Procentaj',
'Coeficienți preț', plus all group headers.
Root cause: every Filament Resource and Page had static properties
'protected static ?string $navigationLabel = "Fișe lucru"' — string
literals baked into class definitions. Static properties don't run
through the translation layer.
Fix in two parts:
1. New translation files with 52 label keys + 12 group keys:
- lang/ro/nav.php — Romanian (identity)
- lang/ru/nav.php — full Russian translations (Заказ-наряды,
Автомобили, Клиенты, Календарь, Моя мастерская, Механики KPI,
Настройки, etc.)
- lang/en/nav.php — English translations (Work orders, Vehicles,
Clients, Calendar, My workshop, Mechanic KPI, Settings, etc.)
Keyed by the Romanian original so lookups map 1:1 —
'nav.label.Fișe lucru' returns 'Заказ-наряды' in RU, 'Work orders'
in EN, 'Fișe lucru' in RO.
2. Python transformer converted 54 files:
- 33 Filament Tenant Resources
- 15 Filament Tenant Pages
- 4 Filament Central Resources
- 1 Filament Central Page
- 1 Widget
Each 'protected static ?string $navigationLabel = "X";' became
'public static function getNavigationLabel(): string { return
__("nav.label.X"); }'. Same treatment for $navigationGroup.
Cleanup: 6 resources already had manually-added getNavigationLabel
methods from an earlier partial effort — those used flat JSON keys
(__("Cereri")) that never resolved. Deduped so only the nav.label.*
version remains.
Untouched (intentional):
- $modelLabel / $pluralModelLabel (used in breadcrumbs and headings —
still hardcoded, next tier of work)
- Section titles, column headers, form field labels (medium priority)
- $navigationSort (numeric, no translation needed)
- $navigationIcon (icon reference)
Suite: 306 passed (853 assertions). Unchanged.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
141 lines
6.5 KiB
PHP
141 lines
6.5 KiB
PHP
<?php
|
||
|
||
namespace App\Filament\Central\Resources;
|
||
|
||
use App\Filament\Central\Resources\PlanResource\Pages;
|
||
use App\Models\Central\Plan;
|
||
use Filament\Actions;
|
||
use Filament\Forms;
|
||
use Filament\Resources\Resource;
|
||
use Filament\Schemas;
|
||
use Filament\Schemas\Components\Utilities\Get;
|
||
use Filament\Schemas\Schema;
|
||
use Filament\Tables;
|
||
use Filament\Tables\Table;
|
||
|
||
class PlanResource extends Resource
|
||
{
|
||
protected static ?string $model = Plan::class;
|
||
|
||
protected static string|\BackedEnum|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||
|
||
public static function getNavigationLabel(): string
|
||
{
|
||
return __('nav.label.Planuri');
|
||
}
|
||
|
||
protected static ?string $modelLabel = 'plan';
|
||
|
||
protected static ?string $pluralModelLabel = 'planuri';
|
||
|
||
protected static ?int $navigationSort = 20;
|
||
|
||
public const FEATURE_OPTIONS = [
|
||
'kanban' => 'Kanban WO',
|
||
'reports' => 'Rapoarte avansate',
|
||
'ai' => 'Asistent AI',
|
||
'pdf' => 'Generare PDF',
|
||
'reverb' => 'WebSocket real-time',
|
||
'api' => 'REST API + tokens',
|
||
'multi_user' => 'Multi-user (>1 cont)',
|
||
'white_label' => 'White-label complet',
|
||
'priority_support' => 'Suport prioritar',
|
||
'custom_domain' => 'Domeniu propriu',
|
||
];
|
||
|
||
public static function form(Schema $schema): Schema
|
||
{
|
||
return $schema->components([
|
||
Schemas\Components\Section::make('Identificare')
|
||
->columns(2)
|
||
->schema([
|
||
Forms\Components\TextInput::make('slug')
|
||
->required()->alphaDash()->unique(ignoreRecord: true)
|
||
->dehydrateStateUsing(fn ($s) => strtolower((string) $s))
|
||
->extraInputAttributes(['style' => 'text-transform:lowercase']),
|
||
Forms\Components\TextInput::make('name')->required()->maxLength(60),
|
||
Forms\Components\Toggle::make('is_active')->label('Activ')->default(true),
|
||
Forms\Components\Toggle::make('is_public')->label('Public (afișat la signup)')->default(true),
|
||
Forms\Components\Toggle::make('is_demo')
|
||
->label('Demo (pentru demonstrații sales)')
|
||
->helperText('Plan ascuns public, folosit pentru tenant-i demo cu features deblocate.')
|
||
->default(false),
|
||
Forms\Components\TextInput::make('trial_days')
|
||
->label('Perioadă trial (zile)')
|
||
->numeric()->placeholder('null = fără trial')
|
||
->helperText('Numărul de zile gratis după ce un tenant alege acest plan.'),
|
||
]),
|
||
Schemas\Components\Section::make('Preț')
|
||
->columns(3)
|
||
->schema([
|
||
Forms\Components\TextInput::make('price_monthly')->label('Preț lunar')->numeric()->required()->suffix(fn (Get $get) => $get('currency') ?? 'MDL'),
|
||
Forms\Components\TextInput::make('price_yearly')->label('Preț anual')->numeric()->helperText('De obicei 10× preț lunar (2 luni gratis).')->suffix(fn (Get $get) => $get('currency') ?? 'MDL'),
|
||
Forms\Components\Select::make('currency')->options(['MDL' => 'MDL', 'EUR' => 'EUR', 'USD' => 'USD'])->default('MDL'),
|
||
]),
|
||
Schemas\Components\Section::make('Funcționalități incluse')
|
||
->columns(2)
|
||
->schema([
|
||
Forms\Components\CheckboxList::make('features')
|
||
->options(self::FEATURE_OPTIONS)
|
||
->columns(2)
|
||
->columnSpanFull(),
|
||
]),
|
||
Schemas\Components\Section::make('Limite')
|
||
->columns(3)
|
||
->schema([
|
||
Forms\Components\TextInput::make('limits.max_users')->label('Max useri')->numeric()->placeholder('∞'),
|
||
Forms\Components\TextInput::make('limits.max_clients')->label('Max clienți')->numeric()->placeholder('∞'),
|
||
Forms\Components\TextInput::make('limits.max_vehicles')->label('Max mașini')->numeric()->placeholder('∞'),
|
||
Forms\Components\TextInput::make('limits.max_work_orders_month')->label('Max fișe/lună')->numeric()->placeholder('∞'),
|
||
Forms\Components\TextInput::make('limits.storage_mb')->label('Storage (MB)')->numeric()->placeholder('∞'),
|
||
Forms\Components\TextInput::make('limits.ai_messages_month')->label('Mesaje AI/lună')->numeric()->placeholder('∞'),
|
||
]),
|
||
]);
|
||
}
|
||
|
||
public static function table(Table $table): Table
|
||
{
|
||
return $table
|
||
->columns([
|
||
Tables\Columns\TextColumn::make('name')
|
||
->searchable()->sortable()
|
||
->weight('bold')
|
||
->description(fn ($record) => $record->is_demo ? '🎬 Demo' : ($record->trial_days ? "🎁 {$record->trial_days} zile trial" : null)),
|
||
Tables\Columns\TextColumn::make('price_monthly')
|
||
->money(fn ($record) => $record->currency)
|
||
->label('Lunar')
|
||
->sortable(),
|
||
Tables\Columns\TextColumn::make('price_yearly')
|
||
->money(fn ($record) => $record->currency)
|
||
->label('Anual'),
|
||
Tables\Columns\TextColumn::make('companies_count')
|
||
->counts('companies')
|
||
->label('Abonați')
|
||
->badge()
|
||
->color('primary'),
|
||
Tables\Columns\TextColumn::make('features')
|
||
->label('Funcționalități')
|
||
->formatStateUsing(fn ($s) => is_array($s) ? count($s) . ' incluse' : '—')
|
||
->badge(),
|
||
Tables\Columns\IconColumn::make('is_active')->boolean()->label('Activ'),
|
||
Tables\Columns\IconColumn::make('is_public')->boolean()->label('Public'),
|
||
])
|
||
->actions([
|
||
Actions\EditAction::make(),
|
||
Actions\DeleteAction::make(),
|
||
])
|
||
->emptyStateHeading('Niciun plan definit')
|
||
->emptyStateDescription('Creează planuri (ex: Free, Basic, Pro) și atribuie-le companiilor.')
|
||
->defaultSort('price_monthly');
|
||
}
|
||
|
||
public static function getPages(): array
|
||
{
|
||
return [
|
||
'index' => Pages\ListPlans::route('/'),
|
||
'create' => Pages\CreatePlan::route('/create'),
|
||
'edit' => Pages\EditPlan::route('/{record}/edit'),
|
||
];
|
||
}
|
||
}
|