From d31a7aec5af89d3c397930bc8cc95e91bb9b671c Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 13:42:50 +0200 Subject: [PATCH 1/6] added missing translations --- src/Pages/Plugins.php | 35 +++++++++++------- src/Resources/TableResource.php | 26 +++++++------- .../TableResource/Pages/ListTables.php | 3 +- .../TableColsRelationManager.php | 36 +++++++++++-------- src/Services/Traits/GenerateInfo.php | 6 ++++ stubs/page.stub | 9 +++-- 6 files changed, 73 insertions(+), 42 deletions(-) diff --git a/src/Pages/Plugins.php b/src/Pages/Plugins.php index d23521e..74ee58a 100644 --- a/src/Pages/Plugins.php +++ b/src/Pages/Plugins.php @@ -32,12 +32,16 @@ class Plugins extends Page implements HasTable protected $listeners = ['pluginRefresh' => '$refresh']; public static ?string $navigationIcon = 'heroicon-o-squares-plus'; - public static ?string $navigationGroup = 'Settings'; public static string $view = 'filament-plugins::pages.plugins'; public function getTitle(): string { - return 'Plugins'; + return __('Plugins'); + } + + public static function getNavigationGroup(): ?string + { + return __('Settings'); } public function table(Table $table): Table @@ -58,7 +62,7 @@ public function disableAction(): Action ->iconButton() ->icon('heroicon-s-x-circle') ->color('danger') - ->tooltip('Disable') + ->tooltip(__('Disable')) ->requiresConfirmation() ->action(function (array $arguments) { $module = Module::find($arguments['item']['module_name']); @@ -80,7 +84,7 @@ public function deleteAction(): Action ->iconButton() ->icon('heroicon-s-trash') ->color('danger') - ->tooltip('Delete') + ->tooltip(__('Delete')) ->requiresConfirmation() ->action(function (array $arguments) { $module = Module::find($arguments['item']['module_name']); @@ -102,7 +106,7 @@ public function activeAction(): Action return Action::make('active') ->iconButton() ->icon('heroicon-s-check-circle') - ->tooltip('Active') + ->tooltip(__('Active')) ->color('success') ->requiresConfirmation() ->action(function (array $arguments) { @@ -133,27 +137,34 @@ public function getHeaderActions(): array if((bool)config('filament-plugins.allow_create')){ return [ Action::make('create') - ->label('Create Plugin') + ->label( + __('Create Plugin')) ->icon('heroicon-o-plus') ->form([ TextInput::make('name') - ->label('Plugin Name') - ->placeholder('e.g. My Plugin') + ->label( + __('Plugin Name')) + ->placeholder( + __('e.g. My Plugin')) ->required(), Textarea::make('description') - ->label('Description') - ->placeholder('e.g. A simple plugin for Filament') + ->label( + __('Description')) + ->placeholder( + __('e.g. A simple plugin for Filament')) ->required(), ColorPicker::make('color')->required(), IconPicker::make('icon')->required() ]) ->action(fn (array $data) => $this->createPlugin($data)), Action::make('import') - ->label('Import Plugin') + ->label( + __('Import Plugin')) ->icon('heroicon-o-arrow-up-on-square') ->form([ FileUpload::make('file') - ->label('Plugin File') + ->label( + __('Plugin File')) ->acceptedFileTypes(['application/zip']) ->required() ->storeFiles(false) diff --git a/src/Resources/TableResource.php b/src/Resources/TableResource.php index 0aed529..55273f7 100644 --- a/src/Resources/TableResource.php +++ b/src/Resources/TableResource.php @@ -73,20 +73,22 @@ public static function table(Table $table): Table Tables\Actions\DeleteAction::make()->iconButton(), Tables\Actions\Action::make('migrate') ->requiresConfirmation() - ->tooltip('Migrate') + ->tooltip( + __('Migrate')) ->color('info') ->iconButton() ->icon('heroicon-s-circle-stack') ->action(function (TableModel $record){ $record->migrate(); Notification::make() - ->title('Migrated') - ->body('Table migrated successfully.') + ->title(__('Migrated')) + ->body(__('Table migrated successfully.')) ->success() ->send(); }), Tables\Actions\Action::make('generate') - ->tooltip('Generate') + ->tooltip( + __('Generate')) ->color('info') ->iconButton() ->icon('heroicon-s-home-modern') @@ -111,8 +113,8 @@ public static function table(Table $table): Table ->action(function (TableModel $record, array $data){ if((!Schema::hasTable($record->name)) && $data['type'] !== 'migrate'){ Notification::make() - ->title('Error') - ->body('Table does not exist please run migrate.') + ->title(__('Error')) + ->body(__('Table does not exist please run migrate.')) ->danger() ->send(); return; @@ -126,8 +128,8 @@ public static function table(Table $table): Table sleep(1); Notification::make() - ->title('Migrated') - ->body('Table migrated successfully.') + ->title(__('Migrated')) + ->body(__('Table migrated successfully.')) ->success() ->send(); return; @@ -138,8 +140,8 @@ public static function table(Table $table): Table if((!$checkIfModelExists) && in_array($data['type'], ['resource', 'page', 'widget'])){ Notification::make() - ->title('Error') - ->body('Model does not exist please generate model first.') + ->title(__('Error')) + ->body(__('Model does not exist please generate model first.')) ->danger() ->send(); return; @@ -180,8 +182,8 @@ public static function table(Table $table): Table $generator->generate(); Notification::make() - ->title('Generated') - ->body('Table generated successfully.') + ->title(__('Generated')) + ->body(__('Table generated successfully.')) ->success() ->send(); }), diff --git a/src/Resources/TableResource/Pages/ListTables.php b/src/Resources/TableResource/Pages/ListTables.php index 78d9aff..277eeb9 100644 --- a/src/Resources/TableResource/Pages/ListTables.php +++ b/src/Resources/TableResource/Pages/ListTables.php @@ -15,7 +15,8 @@ protected function getHeaderActions(): array { return [ Actions\Action::make('create') - ->label('Create Table') + ->label( + __('Create Table')) ->url(route('filament.'.filament()->getCurrentPanel()->getId().'.resources.tables.create', ['module' => request()->get('module')])) ]; } diff --git a/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php b/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php index 060dac1..01c645c 100644 --- a/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php +++ b/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php @@ -64,29 +64,27 @@ public function form(Form $form): Form Forms\Components\Toggle::make('unique'), Forms\Components\Toggle::make('index'), Forms\Components\Toggle::make('foreign') - ->afterStateUpdated(function(Forms\Set $set, Forms\Get $get) { - if($get('foreign') === true) { + ->afterStateUpdated(function (Forms\Set $set, Forms\Get $get) { + if ($get('foreign') === true) { $set('type', 'bigint'); $set('unsigned', true); - } - else { + } else { $set('type', null); $set('unsigned', false); } - }) ->live(), Forms\Components\TextInput::make('foreign_table') ->required() ->columnSpan(2) - ->hidden(fn(Forms\Get $get) => !$get('foreign')), + ->hidden(fn (Forms\Get $get) => !$get('foreign')), Forms\Components\TextInput::make('foreign_col') ->required() ->columnSpan(2) - ->hidden(fn(Forms\Get $get) => !$get('foreign')), + ->hidden(fn (Forms\Get $get) => !$get('foreign')), Forms\Components\Toggle::make('foreign_on_delete_cascade') ->required() - ->hidden(fn(Forms\Get $get) => !$get('foreign')), + ->hidden(fn (Forms\Get $get) => !$get('foreign')), ]); } @@ -125,14 +123,18 @@ public function table(Table $table): Table ->headerActions([ Tables\Actions\CreateAction::make() - ->label('Add Column'), + ->label( + __('Add Column') + ), Tables\Actions\ActionGroup::make([ Tables\Actions\Action::make('id') ->color('info') ->requiresConfirmation() - ->label('Add Id') + ->label( + __('Add Id') + ) ->icon('heroicon-s-plus') - ->action(function(){ + ->action(function () { $this->ownerRecord->tableCols()->create([ 'name' => 'id', 'type' => 'bigint', @@ -145,8 +147,10 @@ public function table(Table $table): Table ->color('info') ->requiresConfirmation() ->icon('heroicon-s-plus') - ->label('Add Timestamps') - ->action(function(){ + ->label( + __('Add Timestamps') + ) + ->action(function () { $this->ownerRecord->tableCols()->createMany( [ [ @@ -166,8 +170,10 @@ public function table(Table $table): Table ->color('info') ->requiresConfirmation() ->icon('heroicon-s-plus') - ->label('Add Soft Deletes') - ->action(function(){ + ->label( + __('Add Soft Deletes') + ) + ->action(function () { $this->ownerRecord->tableCols()->create( [ 'name' => 'deleted_at', diff --git a/src/Services/Traits/GenerateInfo.php b/src/Services/Traits/GenerateInfo.php index 3569474..e9d6398 100644 --- a/src/Services/Traits/GenerateInfo.php +++ b/src/Services/Traits/GenerateInfo.php @@ -20,11 +20,17 @@ private function generateInfo(): void $module->title['ar'] = $this->title; $module->title['en'] = $this->title; $module->title['gr'] = $this->title; + $module->title['de'] = $this->title; + $module->title['nl'] = $this->title; + $module->title['fr'] = $this->title; $module->title['sp'] = $this->title; $module->description = []; $module->description['ar'] = $this->description; $module->description['en'] = $this->description; $module->description['gr'] = $this->description; + $module->description['de'] = $this->description; + $module->description['nl'] = $this->description; + $module->description['fr'] = $this->description; $module->description['sp'] = $this->description; $module->color = $this->color; $module->icon = $this->icon; diff --git a/stubs/page.stub b/stubs/page.stub index 282bdef..abf2425 100644 --- a/stubs/page.stub +++ b/stubs/page.stub @@ -7,12 +7,17 @@ use Filament\Pages\Page; class {{ name }} extends Page { public static string $view = '{{ view }}'; - public static ?string $navigationGroup = '{{ title }}'; public static ?string $navigationLabel = '{{ title }}'; public static ?string $navigationIcon = '{{ icon }}'; public function getTitle(): string { - return '{{ title }}'; + return __('{{ title }}'); } + + public static function getNavigationGroup(): ?string + { + return __('{{ title }}'); + } + } From a18a8ae392bddbb43fbf6eeaa1d24918e156f530 Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 15:18:00 +0200 Subject: [PATCH 2/6] added conversion script. executed conversion script to change __() to trans() --- convert_translations.php | 79 +++++++++++++++++++ lang/en/messages.php | 47 +++++++++++ src/Pages/Plugins.php | 52 ++++++------ src/Resources/TableResource.php | 24 +++--- .../TableResource/Pages/ListTables.php | 2 +- .../TableColsRelationManager.php | 8 +- 6 files changed, 169 insertions(+), 43 deletions(-) create mode 100644 convert_translations.php create mode 100644 lang/en/messages.php diff --git a/convert_translations.php b/convert_translations.php new file mode 100644 index 0000000..2cec21b --- /dev/null +++ b/convert_translations.php @@ -0,0 +1,79 @@ +isDir()) { + continue; + } + + if ($file->getExtension() === 'php') { + processFile($file->getPathname(), $messages); + } + } +} + +// This function processes each PHP file to find and convert __() strings +function processFile($filePath, &$messages) +{ + $content = file_get_contents($filePath); + // Updated regex to exclude __() calls that contain 'Str::' after the opening __(' + preg_match_all("/__\(\s*['\"](?!.*Str::)(.*?)['\"]\s*\)/", $content, $matches, PREG_SET_ORDER); + + foreach ($matches as $match) { + $originalString = $match[1]; // The original string inside __() + // Check if the string contains '{{' and '}}', indicating a variable + if (strpos($originalString, '{{') !== false && strpos($originalString, '}}') !== false) { + continue; // Skip processing this match + } + $key = generateTransKey($originalString); // Generate a key for the trans() function + $messages['plugins'][$key] = $originalString; + + // Prepare the replacement string + $replacement = "trans('filament-plugins::messages.plugins.$key')"; + // Use preg_replace to replace only the first occurrence + $pattern = '/' . preg_quote($match[0], '/') . '/'; + $content = preg_replace($pattern, $replacement, $content, 1); + } + + // Write the modified content back to the file + file_put_contents($filePath, $content); +} + +function generateTransKey($string) +{ + // Handle the case where the string contains variable placeholders + if (strpos($string, '{{') !== false && strpos($string, '}}') !== false) { + return $string; // Return the string as is, assuming it's a variable + } + + // Convert the string to a slug-like format + $key = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '_', $string)); + + // Trim trailing underscores + $key = rtrim($key, '_'); + + return $key; +} + +// This function saves the messages array to a PHP file +function saveMessagesToFile($messages, $filePath) +{ + $export = var_export($messages, true); + $content = " + [ + 'add_column' => 'Add Column', + 'add_id' => 'Add Id', + 'add_timestamps' => 'Add Timestamps', + 'add_soft_deletes' => 'Add Soft Deletes', + 'create_table' => 'Create Table', + 'migrate' => 'Migrate', + 'migrated' => 'Migrated', + 'table_migrated_successfully' => 'Table migrated successfully.', + 'generate' => 'Generate', + 'error' => 'Error', + 'table_does_not_exist_please_run_migrate' => 'Table does not exist please run migrate.', + 'model_does_not_exist_please_generate_model_first' => 'Model does not exist please generate model first.', + 'generated' => 'Generated', + 'table_generated_successfully' => 'Table generated successfully.', + 'plugins' => 'Plugins', + 'settings' => 'Settings', + 'disable' => 'Disable', + 'plugin_disabled' => 'Plugin Disabled', + 'the_plugin_has_been_disabled_successfully' => 'The plugin has been disabled successfully.', + 'delete' => 'Delete', + 'plugin_deleted' => 'Plugin Deleted', + 'the_plugin_has_been_deleted_successfully' => 'The plugin has been deleted successfully.', + 'active' => 'Active', + 'you_need_to_run_autoload' => 'You need to run autoload', + 'you_need_to_run_composer_dump_autoload_before_activating_the_plugin' => 'You need to run composer dump-autoload before activating the plugin.', + 'plugin_enabled' => 'Plugin Enabled', + 'the_plugin_has_been_enabled_successfully' => 'The plugin has been enabled successfully.', + 'create_plugin' => 'Create Plugin', + 'plugin_name' => 'Plugin Name', + 'e_g_my_plugin' => 'e.g. My Plugin', + 'description' => 'Description', + 'e_g_a_simple_plugin_for_filament' => 'e.g. A simple plugin for Filament', + 'import_plugin' => 'Import Plugin', + 'plugin_file' => 'Plugin File', + 'plugin_uploaded' => 'Plugin Uploaded', + 'the_plugin_has_been_uploaded_successfully' => 'The plugin has been uploaded successfully.', + 'plugin_already_exists' => 'Plugin Already Exists', + 'the_plugin_you_are_trying_to_create_already_exists' => 'The plugin you are trying to create already exists.', + 'plugin_generated_success' => 'Plugin Generated Success', + 'the_plugin_has_been_generated_successfully' => 'The plugin has been generated successfully.', + ], +]; diff --git a/src/Pages/Plugins.php b/src/Pages/Plugins.php index 74ee58a..3557dad 100644 --- a/src/Pages/Plugins.php +++ b/src/Pages/Plugins.php @@ -36,12 +36,12 @@ class Plugins extends Page implements HasTable public function getTitle(): string { - return __('Plugins'); + return trans('filament-plugins::messages.plugins.plugins'); } public static function getNavigationGroup(): ?string { - return __('Settings'); + return trans('filament-plugins::messages.plugins.settings'); } public function table(Table $table): Table @@ -62,15 +62,15 @@ public function disableAction(): Action ->iconButton() ->icon('heroicon-s-x-circle') ->color('danger') - ->tooltip(__('Disable')) + ->tooltip(trans('filament-plugins::messages.plugins.disable')) ->requiresConfirmation() ->action(function (array $arguments) { $module = Module::find($arguments['item']['module_name']); $module?->disable(); Notification::make() - ->title(__("Plugin Disabled")) - ->body(__("The plugin has been disabled successfully.")) + ->title(trans('filament-plugins::messages.plugins.plugin_disabled')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_has_been_disabled_successfully')) ->success() ->send(); @@ -84,15 +84,15 @@ public function deleteAction(): Action ->iconButton() ->icon('heroicon-s-trash') ->color('danger') - ->tooltip(__('Delete')) + ->tooltip(trans('filament-plugins::messages.plugins.delete')) ->requiresConfirmation() ->action(function (array $arguments) { $module = Module::find($arguments['item']['module_name']); $module?->delete(); Notification::make() - ->title(__("Plugin Deleted")) - ->body(__("The plugin has been deleted successfully.")) + ->title(trans('filament-plugins::messages.plugins.plugin_deleted')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_has_been_deleted_successfully')) ->success() ->send(); @@ -106,14 +106,14 @@ public function activeAction(): Action return Action::make('active') ->iconButton() ->icon('heroicon-s-check-circle') - ->tooltip(__('Active')) + ->tooltip(trans('filament-plugins::messages.plugins.active')) ->color('success') ->requiresConfirmation() ->action(function (array $arguments) { if(!class_exists(json_decode($arguments['item']['providers'])[0])){ Notification::make() - ->title(__("You need to run autoload")) - ->body(__("You need to run composer dump-autoload before activating the plugin.")) + ->title(trans('filament-plugins::messages.plugins.you_need_to_run_autoload')) + ->body(trans('filament-plugins::messages.plugins.you_need_to_run_composer_dump_autoload_before_activating_the_plugin')) ->danger() ->send(); return; @@ -122,8 +122,8 @@ public function activeAction(): Action $module?->enable(); Notification::make() - ->title(__("Plugin Enabled")) - ->body(__("The plugin has been enabled successfully.")) + ->title(trans('filament-plugins::messages.plugins.plugin_enabled')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_has_been_enabled_successfully')) ->success() ->send(); @@ -138,20 +138,20 @@ public function getHeaderActions(): array return [ Action::make('create') ->label( - __('Create Plugin')) + trans('filament-plugins::messages.plugins.create_plugin')) ->icon('heroicon-o-plus') ->form([ TextInput::make('name') ->label( - __('Plugin Name')) + trans('filament-plugins::messages.plugins.plugin_name')) ->placeholder( - __('e.g. My Plugin')) + trans('filament-plugins::messages.plugins.e_g_my_plugin')) ->required(), Textarea::make('description') ->label( - __('Description')) + trans('filament-plugins::messages.plugins.description')) ->placeholder( - __('e.g. A simple plugin for Filament')) + trans('filament-plugins::messages.plugins.e_g_a_simple_plugin_for_filament')) ->required(), ColorPicker::make('color')->required(), IconPicker::make('icon')->required() @@ -159,12 +159,12 @@ public function getHeaderActions(): array ->action(fn (array $data) => $this->createPlugin($data)), Action::make('import') ->label( - __('Import Plugin')) + trans('filament-plugins::messages.plugins.import_plugin')) ->icon('heroicon-o-arrow-up-on-square') ->form([ FileUpload::make('file') ->label( - __('Plugin File')) + trans('filament-plugins::messages.plugins.plugin_file')) ->acceptedFileTypes(['application/zip']) ->required() ->storeFiles(false) @@ -191,8 +191,8 @@ public function importPlugin(array $data) $zip->close(); Notification::make() - ->title(__("Plugin Uploaded")) - ->body(__("The plugin has been uploaded successfully.")) + ->title(trans('filament-plugins::messages.plugins.plugin_uploaded')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_has_been_uploaded_successfully')) ->success() ->send(); @@ -206,8 +206,8 @@ public function createPlugin(array $data) $checkIfPluginExists = Module::find(Str::of($data['name'])->camel()->ucfirst()->toString()); if($checkIfPluginExists){ Notification::make() - ->title(__("Plugin Already Exists")) - ->body(__("The plugin you are trying to create already exists.")) + ->title(trans('filament-plugins::messages.plugins.plugin_already_exists')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_you_are_trying_to_create_already_exists')) ->danger() ->send(); } @@ -221,8 +221,8 @@ public function createPlugin(array $data) $generator->generate(); Notification::make() - ->title(__("Plugin Generated Success")) - ->body(__("The plugin has been generated successfully.")) + ->title(trans('filament-plugins::messages.plugins.plugin_generated_success')) + ->body(trans('filament-plugins::messages.plugins.the_plugin_has_been_generated_successfully')) ->success() ->send(); } diff --git a/src/Resources/TableResource.php b/src/Resources/TableResource.php index 55273f7..b3c540e 100644 --- a/src/Resources/TableResource.php +++ b/src/Resources/TableResource.php @@ -74,21 +74,21 @@ public static function table(Table $table): Table Tables\Actions\Action::make('migrate') ->requiresConfirmation() ->tooltip( - __('Migrate')) + trans('filament-plugins::messages.plugins.migrate')) ->color('info') ->iconButton() ->icon('heroicon-s-circle-stack') ->action(function (TableModel $record){ $record->migrate(); Notification::make() - ->title(__('Migrated')) - ->body(__('Table migrated successfully.')) + ->title(trans('filament-plugins::messages.plugins.migrated')) + ->body(trans('filament-plugins::messages.plugins.table_migrated_successfully')) ->success() ->send(); }), Tables\Actions\Action::make('generate') ->tooltip( - __('Generate')) + trans('filament-plugins::messages.plugins.generate')) ->color('info') ->iconButton() ->icon('heroicon-s-home-modern') @@ -113,8 +113,8 @@ public static function table(Table $table): Table ->action(function (TableModel $record, array $data){ if((!Schema::hasTable($record->name)) && $data['type'] !== 'migrate'){ Notification::make() - ->title(__('Error')) - ->body(__('Table does not exist please run migrate.')) + ->title(trans('filament-plugins::messages.plugins.error')) + ->body(trans('filament-plugins::messages.plugins.table_does_not_exist_please_run_migrate')) ->danger() ->send(); return; @@ -128,8 +128,8 @@ public static function table(Table $table): Table sleep(1); Notification::make() - ->title(__('Migrated')) - ->body(__('Table migrated successfully.')) + ->title(trans('filament-plugins::messages.plugins.migrated')) + ->body(trans('filament-plugins::messages.plugins.table_migrated_successfully')) ->success() ->send(); return; @@ -140,8 +140,8 @@ public static function table(Table $table): Table if((!$checkIfModelExists) && in_array($data['type'], ['resource', 'page', 'widget'])){ Notification::make() - ->title(__('Error')) - ->body(__('Model does not exist please generate model first.')) + ->title(trans('filament-plugins::messages.plugins.error')) + ->body(trans('filament-plugins::messages.plugins.model_does_not_exist_please_generate_model_first')) ->danger() ->send(); return; @@ -182,8 +182,8 @@ public static function table(Table $table): Table $generator->generate(); Notification::make() - ->title(__('Generated')) - ->body(__('Table generated successfully.')) + ->title(trans('filament-plugins::messages.plugins.generated')) + ->body(trans('filament-plugins::messages.plugins.table_generated_successfully')) ->success() ->send(); }), diff --git a/src/Resources/TableResource/Pages/ListTables.php b/src/Resources/TableResource/Pages/ListTables.php index 277eeb9..0c8deed 100644 --- a/src/Resources/TableResource/Pages/ListTables.php +++ b/src/Resources/TableResource/Pages/ListTables.php @@ -16,7 +16,7 @@ protected function getHeaderActions(): array return [ Actions\Action::make('create') ->label( - __('Create Table')) + trans('filament-plugins::messages.plugins.create_table')) ->url(route('filament.'.filament()->getCurrentPanel()->getId().'.resources.tables.create', ['module' => request()->get('module')])) ]; } diff --git a/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php b/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php index 01c645c..f0466c8 100644 --- a/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php +++ b/src/Resources/TableResource/RelationManagers/TableColsRelationManager.php @@ -124,14 +124,14 @@ public function table(Table $table): Table Tables\Actions\CreateAction::make() ->label( - __('Add Column') + trans('filament-plugins::messages.plugins.add_column') ), Tables\Actions\ActionGroup::make([ Tables\Actions\Action::make('id') ->color('info') ->requiresConfirmation() ->label( - __('Add Id') + trans('filament-plugins::messages.plugins.add_id') ) ->icon('heroicon-s-plus') ->action(function () { @@ -148,7 +148,7 @@ public function table(Table $table): Table ->requiresConfirmation() ->icon('heroicon-s-plus') ->label( - __('Add Timestamps') + trans('filament-plugins::messages.plugins.add_timestamps') ) ->action(function () { $this->ownerRecord->tableCols()->createMany( @@ -171,7 +171,7 @@ public function table(Table $table): Table ->requiresConfirmation() ->icon('heroicon-s-plus') ->label( - __('Add Soft Deletes') + trans('filament-plugins::messages.plugins.add_soft_deletes') ) ->action(function () { $this->ownerRecord->tableCols()->create( From 01e217a6c6f61d35573d93d46af49ddc06dbc406 Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 15:30:54 +0200 Subject: [PATCH 3/6] now also stubs where possible are converted --- convert_translations.php | 6 +- lang/en/messages.php | 95 +++++++++++++----------- stubs/FormBuilder/BuilderController.stub | 6 +- stubs/FormBuilder/Form.stub | 2 +- stubs/FormBuilder/FormClass.stub | 2 +- stubs/controller-request.stub | 6 +- stubs/controller.stub | 6 +- stubs/create.stub | 4 +- stubs/edit.stub | 6 +- stubs/table.stub | 2 +- stubs/view.stub | 6 +- 11 files changed, 76 insertions(+), 65 deletions(-) diff --git a/convert_translations.php b/convert_translations.php index 2cec21b..61259cb 100644 --- a/convert_translations.php +++ b/convert_translations.php @@ -1,7 +1,7 @@ getExtension() === 'php') { + // Check if the file is a PHP or STUB file + $fileExtension = $file->getExtension(); + if ($fileExtension === 'php' || $fileExtension === 'stub') { processFile($file->getPathname(), $messages); } } diff --git a/lang/en/messages.php b/lang/en/messages.php index ede68cf..c74525b 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -1,47 +1,56 @@ - [ - 'add_column' => 'Add Column', - 'add_id' => 'Add Id', - 'add_timestamps' => 'Add Timestamps', - 'add_soft_deletes' => 'Add Soft Deletes', - 'create_table' => 'Create Table', - 'migrate' => 'Migrate', - 'migrated' => 'Migrated', - 'table_migrated_successfully' => 'Table migrated successfully.', - 'generate' => 'Generate', - 'error' => 'Error', - 'table_does_not_exist_please_run_migrate' => 'Table does not exist please run migrate.', - 'model_does_not_exist_please_generate_model_first' => 'Model does not exist please generate model first.', - 'generated' => 'Generated', - 'table_generated_successfully' => 'Table generated successfully.', - 'plugins' => 'Plugins', - 'settings' => 'Settings', - 'disable' => 'Disable', - 'plugin_disabled' => 'Plugin Disabled', - 'the_plugin_has_been_disabled_successfully' => 'The plugin has been disabled successfully.', - 'delete' => 'Delete', - 'plugin_deleted' => 'Plugin Deleted', - 'the_plugin_has_been_deleted_successfully' => 'The plugin has been deleted successfully.', - 'active' => 'Active', - 'you_need_to_run_autoload' => 'You need to run autoload', - 'you_need_to_run_composer_dump_autoload_before_activating_the_plugin' => 'You need to run composer dump-autoload before activating the plugin.', - 'plugin_enabled' => 'Plugin Enabled', - 'the_plugin_has_been_enabled_successfully' => 'The plugin has been enabled successfully.', - 'create_plugin' => 'Create Plugin', - 'plugin_name' => 'Plugin Name', - 'e_g_my_plugin' => 'e.g. My Plugin', - 'description' => 'Description', - 'e_g_a_simple_plugin_for_filament' => 'e.g. A simple plugin for Filament', - 'import_plugin' => 'Import Plugin', - 'plugin_file' => 'Plugin File', - 'plugin_uploaded' => 'Plugin Uploaded', - 'the_plugin_has_been_uploaded_successfully' => 'The plugin has been uploaded successfully.', - 'plugin_already_exists' => 'Plugin Already Exists', - 'the_plugin_you_are_trying_to_create_already_exists' => 'The plugin you are trying to create already exists.', - 'plugin_generated_success' => 'Plugin Generated Success', - 'the_plugin_has_been_generated_successfully' => 'The plugin has been generated successfully.', - ], + 'plugins' => + [ + 'save' => 'Save', + 'delete' => 'Delete', + 'cancel' => 'Cancel', + 'edit' => 'Edit', + 'updated_successfully' => 'updated successfully', + 'deleted_successfully' => 'deleted successfully', + 'edit' => 'Edit', + 'create' => 'Create', + 'has_been_deleted' => 'Has Been Deleted', + 'add_column' => 'Add Column', + 'add_id' => 'Add Id', + 'add_timestamps' => 'Add Timestamps', + 'add_soft_deletes' => 'Add Soft Deletes', + 'create_table' => 'Create Table', + 'migrate' => 'Migrate', + 'migrated' => 'Migrated', + 'table_migrated_successfully' => 'Table migrated successfully.', + 'generate' => 'Generate', + 'error' => 'Error', + 'table_does_not_exist_please_run_migrate' => 'Table does not exist please run migrate.', + 'model_does_not_exist_please_generate_model_first' => 'Model does not exist please generate model first.', + 'generated' => 'Generated', + 'table_generated_successfully' => 'Table generated successfully.', + 'plugins' => 'Plugins', + 'settings' => 'Settings', + 'disable' => 'Disable', + 'plugin_disabled' => 'Plugin Disabled', + 'the_plugin_has_been_disabled_successfully' => 'The plugin has been disabled successfully.', + 'delete' => 'Delete', + 'plugin_deleted' => 'Plugin Deleted', + 'the_plugin_has_been_deleted_successfully' => 'The plugin has been deleted successfully.', + 'active' => 'Active', + 'you_need_to_run_autoload' => 'You need to run autoload', + 'you_need_to_run_composer_dump_autoload_before_activating_the_plugin' => 'You need to run composer dump-autoload before activating the plugin.', + 'plugin_enabled' => 'Plugin Enabled', + 'the_plugin_has_been_enabled_successfully' => 'The plugin has been enabled successfully.', + 'create_plugin' => 'Create Plugin', + 'plugin_name' => 'Plugin Name', + 'e_g_my_plugin' => 'e.g. My Plugin', + 'description' => 'Description', + 'e_g_a_simple_plugin_for_filament' => 'e.g. A simple plugin for Filament', + 'import_plugin' => 'Import Plugin', + 'plugin_file' => 'Plugin File', + 'plugin_uploaded' => 'Plugin Uploaded', + 'the_plugin_has_been_uploaded_successfully' => 'The plugin has been uploaded successfully.', + 'plugin_already_exists' => 'Plugin Already Exists', + 'the_plugin_you_are_trying_to_create_already_exists' => 'The plugin you are trying to create already exists.', + 'plugin_generated_success' => 'Plugin Generated Success', + 'the_plugin_has_been_generated_successfully' => 'The plugin has been generated successfully.', + ], ]; diff --git a/stubs/FormBuilder/BuilderController.stub b/stubs/FormBuilder/BuilderController.stub index bbb034f..af56eaa 100644 --- a/stubs/FormBuilder/BuilderController.stub +++ b/stubs/FormBuilder/BuilderController.stub @@ -67,7 +67,7 @@ class {{ name }} extends Controller validation: [ {{ validation }} ], - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -119,7 +119,7 @@ class {{ name }} extends Controller validation: [ {{ validationEdit }} ], - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -138,7 +138,7 @@ class {{ name }} extends Controller { $response = Tomato::destroy( model: $model, - message: __('{{ title }} deleted successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.deleted_successfully'), redirect: 'admin.{{ table }}.index', ); diff --git a/stubs/FormBuilder/Form.stub b/stubs/FormBuilder/Form.stub index 4cfe4ea..5f41a92 100644 --- a/stubs/FormBuilder/Form.stub +++ b/stubs/FormBuilder/Form.stub @@ -1,3 +1,3 @@ - + diff --git a/stubs/FormBuilder/FormClass.stub b/stubs/FormBuilder/FormClass.stub index a7263a5..3510e83 100644 --- a/stubs/FormBuilder/FormClass.stub +++ b/stubs/FormBuilder/FormClass.stub @@ -28,7 +28,7 @@ class {{ name }} extends AbstractForm return [ {{ cols }} Submit::make() - ->label(__('Save')), + ->label(trans('filament-plugins::messages.plugins.save')), ]; } diff --git a/stubs/controller-request.stub b/stubs/controller-request.stub index 403b63e..3925b5a 100644 --- a/stubs/controller-request.stub +++ b/stubs/controller-request.stub @@ -63,7 +63,7 @@ class {{ name }} extends Controller $response = Tomato::store( request: $request, model: {{ model }}::class, - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -108,7 +108,7 @@ class {{ name }} extends Controller $response = Tomato::update( request: $request, model: $model, - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -127,7 +127,7 @@ class {{ name }} extends Controller { $response = Tomato::destroy( model: $model, - message: __('{{ title }} deleted successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.deleted_successfully'), redirect: 'admin.{{ table }}.index', ); diff --git a/stubs/controller.stub b/stubs/controller.stub index ac1402a..e8ce011 100644 --- a/stubs/controller.stub +++ b/stubs/controller.stub @@ -66,7 +66,7 @@ class {{ name }} extends Controller validation: [ {{ validation }} ], - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -114,7 +114,7 @@ class {{ name }} extends Controller validation: [ {{ validationEdit }} ], - message: __('{{ title }} updated successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.updated_successfully'), redirect: 'admin.{{ table }}.index', ); @@ -133,7 +133,7 @@ class {{ name }} extends Controller { $response = Tomato::destroy( model: $model, - message: __('{{ title }} deleted successfully'), + message: __('{{ title }}') trans('filament-plugins::messages.plugins.deleted_successfully'), redirect: 'admin.{{ table }}.index', ); diff --git a/stubs/create.stub b/stubs/create.stub index e9990fd..b8da04e 100644 --- a/stubs/create.stub +++ b/stubs/create.stub @@ -3,8 +3,8 @@ {{ cols }}
- - + +
diff --git a/stubs/edit.stub b/stubs/edit.stub index 3799d09..7065218 100644 --- a/stubs/edit.stub +++ b/stubs/edit.stub @@ -3,14 +3,14 @@ {{ cols }}
- + - + method="delete" label="{{trans('filament-plugins::messages.plugins.delete')}}" /> +
diff --git a/stubs/table.stub b/stubs/table.stub index 66063d7..17117ea 100644 --- a/stubs/table.stub +++ b/stubs/table.stub @@ -58,7 +58,7 @@ class {{ name }} extends AbstractTable ->bulkAction( label: trans('tomato-admin::global.crud.delete'), each: fn ({{ model }} $model) => $model->delete(), - after: fn () => Toast::danger(__('{{ title }} Has Been Deleted'))->autoDismiss(2), + after: fn () => Toast::danger(__('{{ title }}') trans('filament-plugins::messages.plugins.has_been_deleted'))->autoDismiss(2), confirm: true ) ->defaultSort('id', 'desc') diff --git a/stubs/view.stub b/stubs/view.stub index 0fe1d98..d39e27a 100644 --- a/stubs/view.stub +++ b/stubs/view.stub @@ -3,13 +3,13 @@ {{ cols }}
- + - + method="delete" label="{{trans('filament-plugins::messages.plugins.delete')}}" /> +
From cf899ceccd1c12764151879056150fc9e2ba81ae Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 17:03:22 +0200 Subject: [PATCH 4/6] small translations added --- lang/en/messages.php | 3 +-- resources/views/pages/table.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lang/en/messages.php b/lang/en/messages.php index c74525b..952e90d 100644 --- a/lang/en/messages.php +++ b/lang/en/messages.php @@ -9,7 +9,6 @@ 'edit' => 'Edit', 'updated_successfully' => 'updated successfully', 'deleted_successfully' => 'deleted successfully', - 'edit' => 'Edit', 'create' => 'Create', 'has_been_deleted' => 'Has Been Deleted', 'add_column' => 'Add Column', @@ -22,6 +21,7 @@ 'table_migrated_successfully' => 'Table migrated successfully.', 'generate' => 'Generate', 'error' => 'Error', + 'docs' => 'Docs', 'table_does_not_exist_please_run_migrate' => 'Table does not exist please run migrate.', 'model_does_not_exist_please_generate_model_first' => 'Model does not exist please generate model first.', 'generated' => 'Generated', @@ -31,7 +31,6 @@ 'disable' => 'Disable', 'plugin_disabled' => 'Plugin Disabled', 'the_plugin_has_been_disabled_successfully' => 'The plugin has been disabled successfully.', - 'delete' => 'Delete', 'plugin_deleted' => 'Plugin Deleted', 'the_plugin_has_been_deleted_successfully' => 'The plugin has been deleted successfully.', 'active' => 'Active', diff --git a/resources/views/pages/table.blade.php b/resources/views/pages/table.blade.php index 5e9fb60..ed332b7 100644 --- a/resources/views/pages/table.blade.php +++ b/resources/views/pages/table.blade.php @@ -29,7 +29,7 @@
@if((bool)config('filament-plugins.allow_generator')) - + @@ -56,7 +56,7 @@ @endif @if($item->docs) - + From e60d9c47d9e3e68b068b58f347391f4c2747fa74 Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 17:05:59 +0200 Subject: [PATCH 5/6] trans in blade echo wrapper --- resources/views/pages/table.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/table.blade.php b/resources/views/pages/table.blade.php index ed332b7..d159070 100644 --- a/resources/views/pages/table.blade.php +++ b/resources/views/pages/table.blade.php @@ -29,7 +29,7 @@
@if((bool)config('filament-plugins.allow_generator')) - + From 5810cab06460a3e8b7437c45bf898d3583eb808a Mon Sep 17 00:00:00 2001 From: Eelco Date: Wed, 17 Apr 2024 17:46:14 +0200 Subject: [PATCH 6/6] added dutch translations --- resources/lang/nl/messages.php | 55 ++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 resources/lang/nl/messages.php diff --git a/resources/lang/nl/messages.php b/resources/lang/nl/messages.php new file mode 100644 index 0000000..1e51ead --- /dev/null +++ b/resources/lang/nl/messages.php @@ -0,0 +1,55 @@ + + [ + 'save' => 'Opslaan', + 'delete' => 'Verwijderen', + 'cancel' => 'Annuleren', + 'edit' => 'Bewerk', + 'updated_successfully' => 'succesvol geupdatet', + 'deleted_successfully' => 'met succes verwijderd', + 'create' => 'Aanmaken', + 'has_been_deleted' => 'is verwijderd', + 'add_column' => 'Kolom toevoegen', + 'add_id' => 'Id toevoegen', + 'add_timestamps' => 'Timestamps toevoegen', + 'add_soft_deletes' => 'Soft Deletes toevoegen', + 'create_table' => 'Tabel maken', + 'migrate' => 'Migreren', + 'migrated' => 'Gemigreerd', + 'table_migrated_successfully' => 'Tabel is succesvol gemigreerd.', + 'generate' => 'Genereer', + 'error' => 'Fout', + 'docs' => 'Docs', + 'table_does_not_exist_please_run_migrate' => 'Tabel bestaat niet. Voer de migratie uit.', + 'model_does_not_exist_please_generate_model_first' => 'Model bestaat niet, genereer eerst een model.', + 'generated' => 'Gegenereerd', + 'table_generated_successfully' => 'Tabel is succesvol gegenereerd.', + 'plugins' => 'Plug-ins', + 'settings' => 'Instellingen', + 'disable' => 'Uitschakelen', + 'plugin_disabled' => 'Plug-in Uitgeschakeld', + 'the_plugin_has_been_disabled_successfully' => 'De plug-in is succesvol uitgeschakeld.', + 'plugin_deleted' => 'Plug-in Verwijderd', + 'the_plugin_has_been_deleted_successfully' => 'The plug-in is succesvol verwijderd.', + 'active' => 'Actief', + 'you_need_to_run_autoload' => 'U moet `autoload` uitvoeren', + 'you_need_to_run_composer_dump_autoload_before_activating_the_plugin' => 'U moet `composer dump-autoload` uitvoeren voordat u de plug-in activeert.', + 'plugin_enabled' => 'Plug-in ingeschakeld', + 'the_plugin_has_been_enabled_successfully' => 'De plug-in is succesvol ingeschakeld.', + 'create_plugin' => 'Plug-in maken', + 'plugin_name' => 'Naam Plug-in', + 'e_g_my_plugin' => 'vb. Mijn Plugin', + 'description' => 'Beschrijving', + 'e_g_a_simple_plugin_for_filament' => 'vb. Een eenvoudige plug-in voor Filament', + 'import_plugin' => 'Importeer Plug-in', + 'plugin_file' => 'Plug-in Bestand', + 'plugin_uploaded' => 'Plug-in geüpload', + 'the_plugin_has_been_uploaded_successfully' => 'De plug-in is succesvol geüpload.', + 'plugin_already_exists' => 'Plug-in bestaat al', + 'the_plugin_you_are_trying_to_create_already_exists' => 'De plug-in die u probeert te maken bestaat al.', + 'plugin_generated_success' => 'Plug-in succesvol gegenereerd', + 'the_plugin_has_been_generated_successfully' => 'De plug-in is succesvol gegenereerd.', + ], +];