diff --git a/composer.json b/composer.json index e5d6ee0..4e96738 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require": { "filament/filament": "^3.0", "appstract/laravel-opcache": "^4.0.2", - "nesbot/carbon": "^2.0" + "nesbot/carbon": "^2.0|^3.0" }, "extra": { "laravel": { diff --git a/resources/lang/en/actions.php b/resources/lang/en/actions.php new file mode 100644 index 0000000..2ad407e --- /dev/null +++ b/resources/lang/en/actions.php @@ -0,0 +1,15 @@ + [ + 'label' => 'Compile Scripts', + ], + + 'clear' => [ + 'label' => 'Clear OPcache', + ], + +]; diff --git a/resources/lang/en/notifications.php b/resources/lang/en/notifications.php new file mode 100644 index 0000000..b470d45 --- /dev/null +++ b/resources/lang/en/notifications.php @@ -0,0 +1,20 @@ + [ + 'title' => 'Scripts Compiled', + 'body' => ':compiled_count files compiled successfully.', + ], + + 'cleared' => [ + 'title' => 'OPcache Cleared', + ], + + 'Disabled' => [ + 'title' => 'OPcache Disabled', + ], + +]; diff --git a/resources/lang/en/pages.php b/resources/lang/en/pages.php new file mode 100644 index 0000000..0ce24cc --- /dev/null +++ b/resources/lang/en/pages.php @@ -0,0 +1,17 @@ + [ + 'title' => 'OPcache Config', + 'navigation_label' => 'Config', + ], + + 'status' => [ + 'title' => 'OPcache Status', + 'navigation_label' => 'Status', + ], + +]; diff --git a/resources/lang/en/table.php b/resources/lang/en/table.php new file mode 100644 index 0000000..37b93a2 --- /dev/null +++ b/resources/lang/en/table.php @@ -0,0 +1,12 @@ + [ + 'key' => 'Key', + 'value' => 'Value', + ], + +]; diff --git a/resources/lang/en/tabs.php b/resources/lang/en/tabs.php new file mode 100644 index 0000000..2216885 --- /dev/null +++ b/resources/lang/en/tabs.php @@ -0,0 +1,16 @@ + 'Blacklist', + 'directives' => 'Directives', + 'jit' => 'JIT', + 'lifecycle' => 'Lifecycle', + 'memory' => 'Memory', + 'statistics' => 'Statistics', + 'strings' => 'Strings', + 'version' => 'Version', + +]; diff --git a/resources/lang/en/widgets.php b/resources/lang/en/widgets.php new file mode 100644 index 0000000..df2c4f8 --- /dev/null +++ b/resources/lang/en/widgets.php @@ -0,0 +1,23 @@ + [ + 'heading' => 'OPcache Hits', + 'categories' => [ + 'hits' => 'Hits', + 'misses' => 'Misses', + ], + ], + + 'memory' => [ + 'heading' => 'OPcache Memory Usage', + 'categories' => [ + 'used' => 'Used', + 'free' => 'Free', + ], + ], + +]; diff --git a/resources/lang/ru/actions.php b/resources/lang/ru/actions.php new file mode 100644 index 0000000..db7db08 --- /dev/null +++ b/resources/lang/ru/actions.php @@ -0,0 +1,15 @@ + [ + 'label' => 'Скомпилировать скрипты', + ], + + 'clear' => [ + 'label' => 'Очистить OPcache', + ], + +]; diff --git a/resources/lang/ru/notifications.php b/resources/lang/ru/notifications.php new file mode 100644 index 0000000..97f2778 --- /dev/null +++ b/resources/lang/ru/notifications.php @@ -0,0 +1,20 @@ + [ + 'title' => 'Скрипты скомпилированы', + 'body' => 'Успешно скомпилировано :compiled_count файлов.', + ], + + 'cleared' => [ + 'title' => 'OPcache очищен', + ], + + 'Disabled' => [ + 'title' => 'OPcache выключен', + ], + +]; diff --git a/resources/lang/ru/pages.php b/resources/lang/ru/pages.php new file mode 100644 index 0000000..a5d7269 --- /dev/null +++ b/resources/lang/ru/pages.php @@ -0,0 +1,17 @@ + [ + 'title' => 'Параметры OPcache', + 'navigation_label' => 'Параметры', + ], + + 'status' => [ + 'title' => 'Состояние OPcache', + 'navigation_label' => 'Состояние', + ], + +]; diff --git a/resources/lang/ru/table.php b/resources/lang/ru/table.php new file mode 100644 index 0000000..f2f2e6f --- /dev/null +++ b/resources/lang/ru/table.php @@ -0,0 +1,12 @@ + [ + 'key' => 'Ключ', + 'value' => 'Значение', + ], + +]; diff --git a/resources/lang/ru/tabs.php b/resources/lang/ru/tabs.php new file mode 100644 index 0000000..2bbde4a --- /dev/null +++ b/resources/lang/ru/tabs.php @@ -0,0 +1,16 @@ + 'Чёрный список', + 'directives' => 'Директивы', + 'jit' => 'JIT', + 'lifecycle' => 'Жизненный цикл', + 'memory' => 'Память', + 'statistics' => 'Статистика', + 'strings' => 'Строки', + 'version' => 'Версия', + +]; diff --git a/resources/lang/ru/widgets.php b/resources/lang/ru/widgets.php new file mode 100644 index 0000000..7d57b80 --- /dev/null +++ b/resources/lang/ru/widgets.php @@ -0,0 +1,23 @@ + [ + 'heading' => 'Попадания в OPcache', + 'categories' => [ + 'hits' => 'Попадания', + 'misses' => 'Промахи', + ], + ], + + 'memory' => [ + 'heading' => 'Использование памяти OPcache', + 'categories' => [ + 'used' => 'Использовано', + 'free' => 'Свободно', + ], + ], + +]; diff --git a/resources/views/status.blade.php b/resources/views/status.blade.php index 5fea47f..09223c6 100644 --- a/resources/views/status.blade.php +++ b/resources/views/status.blade.php @@ -7,7 +7,7 @@ :active="strtolower($tab) == $activeTab" wire:click="$set('activeTab', '{{ strtolower($tab) }}')" > - {{ $tab }} + {{ __("filament-opcache::tabs.$tab") }} @endforeach @@ -17,8 +17,8 @@ - Key - Value + {{ __('filament-opcache::table.headers.key') }} + {{ __('filament-opcache::table.headers.value') }} @foreach($$activeTab as $key => $value) diff --git a/src/FilamentOpcachePlugin.php b/src/FilamentOpcachePlugin.php index 0c6cd75..673fcd2 100644 --- a/src/FilamentOpcachePlugin.php +++ b/src/FilamentOpcachePlugin.php @@ -1,5 +1,7 @@ name(static::$name) + ->hasTranslations() ->hasViews(); } } diff --git a/src/Pages/Config.php b/src/Pages/Config.php index 6b7f7c4..bb5f4d0 100644 --- a/src/Pages/Config.php +++ b/src/Pages/Config.php @@ -5,16 +5,9 @@ namespace STS\FilamentOpcache\Pages; use Appstract\Opcache\OpcacheFacade; -use Filament\Actions\Action; -use Filament\Notifications\Notification; -use Filament\Pages\Page; class Config extends Page { - protected static ?string $title = 'OPcache Config'; - - protected static ?string $navigationLabel = 'Config'; - protected static ?string $slug = 'opcache-config'; protected static ?string $navigationIcon = 'heroicon-o-cog'; @@ -23,37 +16,10 @@ class Config extends Page protected static ?string $navigationGroup = 'OPcache'; - public array $tabs = ['Directives', 'Version', 'Blacklist']; + public array $tabs = ['directives', 'version', 'blacklist']; public string $activeTab = 'directives'; - /** @noinspection DuplicatedCode */ - protected function getActions(): array - { - return [ - Action::make('compile') - ->label('Compile Scripts') - ->action(function () { - $result = OpcacheFacade::compile(true); - - Notification::make() - ->title('Scripts Compiled') - ->body($result['compiled_count'] . ' files compiled successfully.') - ->success() - ->send(); - }), - Action::make('clear') - ->label('Clear OPcache') - ->action(function () { - if (OpcacheFacade::clear()) { - Notification::make()->title('OPcache Cleared')->success()->send(); - } else { - Notification::make()->title('OPcache Disabled')->warning()->send(); - } - }), - ]; - } - protected function getViewData(): array { $config = OpcacheFacade::getConfig(); diff --git a/src/Pages/Page.php b/src/Pages/Page.php new file mode 100644 index 0000000..61f6856 --- /dev/null +++ b/src/Pages/Page.php @@ -0,0 +1,70 @@ +lower()->value(); + + $translations = __('filament-opcache::pages'); + + return $translations[$key] ?? null; + } + + protected function getActions(): array + { + return [ + Action::make('compile') + ->label(__('filament-opcache::actions.compile.label')) + ->action(function () { + $result = OpcacheFacade::compile(true); + + Notification::make() + ->title(__('filament-opcache::notifications.compiled.title')) + ->body(__('filament-opcache::notifications.compiled.body', $result)) + ->success() + ->send(); + }), + + Action::make('clear') + ->label(__('filament-opcache::actions.clear.label')) + ->action(function () { + if (OpcacheFacade::clear()) { + Notification::make() + ->title(__('filament-opcache::notifications.cleared.title')) + ->success() + ->send(); + } else { + Notification::make() + ->title(__('filament-opcache::notifications.disabled.title')) + ->warning() + ->send(); + } + }), + ]; + } +} diff --git a/src/Pages/Status.php b/src/Pages/Status.php index 1f67e24..4df1648 100644 --- a/src/Pages/Status.php +++ b/src/Pages/Status.php @@ -1,21 +1,16 @@ label('Compile Scripts') - ->action(function () { - $result = OpcacheFacade::compile(true); - - Notification::make() - ->title('Scripts Compiled') - ->body($result['compiled_count'] . ' files compiled successfully.') - ->success() - ->send(); - }), - Action::make('clear') - ->label('Clear OPcache') - ->action(function () { - if (OpcacheFacade::clear()) { - Notification::make()->title('OPcache Cleared')->success()->send(); - } else { - Notification::make()->title('OPcache Disabled')->warning()->send(); - } - }), - ]; - } - protected function getViewData(): array { $status = OpcacheFacade::getStatus(); diff --git a/src/Widgets/OpcacheHitsWidget.php b/src/Widgets/OpcacheHitsWidget.php index f86dd12..c2a5bce 100644 --- a/src/Widgets/OpcacheHitsWidget.php +++ b/src/Widgets/OpcacheHitsWidget.php @@ -8,8 +8,6 @@ class OpcacheHitsWidget extends PercentageChart { - protected static ?string $heading = 'OPcache Hits'; - protected static ?string $pollingInterval = '10s'; protected static ?string $maxHeight = '200px'; @@ -18,9 +16,9 @@ protected function getData(): array { $status = OpcacheFacade::getStatus(); - return $this->chartDataFor('Memory', - 'Hits', $status['opcache_statistics']['hits'], - 'Misses', $status['opcache_statistics']['misses'] + return $this->chartDataFor('Hits', + __('filament-opcache::widgets.hits.categories.hits'), $status['opcache_statistics']['hits'], + __('filament-opcache::widgets.hits.categories.misses'), $status['opcache_statistics']['misses'] ); } } diff --git a/src/Widgets/OpcacheMemoryWidget.php b/src/Widgets/OpcacheMemoryWidget.php index 8fa59cb..e3688cb 100644 --- a/src/Widgets/OpcacheMemoryWidget.php +++ b/src/Widgets/OpcacheMemoryWidget.php @@ -8,8 +8,6 @@ class OpcacheMemoryWidget extends PercentageChart { - protected static ?string $heading = 'OPcache Memory Usage'; - protected static ?string $pollingInterval = '10s'; protected static ?string $maxHeight = '200px'; @@ -19,8 +17,8 @@ protected function getData(): array $status = OpcacheFacade::getStatus(); return $this->chartDataFor('Memory', - 'Used', $status['memory_usage']['used_memory'], - 'Free', $status['memory_usage']['free_memory'] + __('filament-opcache::widgets.memory.categories.used'), $status['memory_usage']['used_memory'], + __('filament-opcache::widgets.memory.categories.free'), $status['memory_usage']['free_memory'] ); } } diff --git a/src/Widgets/PercentageChart.php b/src/Widgets/PercentageChart.php index aa9ca0b..92b9104 100644 --- a/src/Widgets/PercentageChart.php +++ b/src/Widgets/PercentageChart.php @@ -5,9 +5,28 @@ namespace STS\FilamentOpcache\Widgets; use Filament\Widgets\PieChartWidget; +use Illuminate\Contracts\Support\Htmlable; abstract class PercentageChart extends PieChartWidget { + public function getHeading(): string | Htmlable | null + { + $translations = static::getTranslations(); + + return $translations['heading'] ?? parent::getHeading(); + } + + protected static function getTranslations(): ?array + { + $key = str(class_basename(static::class)) + ->ltrim('OpCache')->rtrim('Widget') + ->lower()->value(); + + $translations = __('filament-opcache::widgets'); + + return $translations[$key] ?? null; + } + protected function chartDataFor($title, $labelA, $valueA, $labelB, $valueB): array { return [