From 470c0cb390aa8ca5ada91a1a458b9d84b00b7370 Mon Sep 17 00:00:00 2001 From: Giuseppe Criscione <18699708+giuscris@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:36:54 +0100 Subject: [PATCH] Remove `TranslatedException::getLanguageString()` --- formwork/src/Exceptions/TranslatedException.php | 9 --------- formwork/src/Panel/Controllers/BackupController.php | 6 +++--- formwork/src/Panel/Controllers/PagesController.php | 8 ++++---- formwork/src/Panel/Controllers/UsersController.php | 4 ++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/formwork/src/Exceptions/TranslatedException.php b/formwork/src/Exceptions/TranslatedException.php index e272df3c..a0f7e2d0 100644 --- a/formwork/src/Exceptions/TranslatedException.php +++ b/formwork/src/Exceptions/TranslatedException.php @@ -3,7 +3,6 @@ namespace Formwork\Exceptions; use Exception; -use Formwork\App; class TranslatedException extends Exception { @@ -27,12 +26,4 @@ class TranslatedException extends Exception { return $this->languageString; } - - /** - * Get localized message - */ - public function getTranslatedMessage(): string - { - return App::instance()->translations()->getCurrent()->translate($this->languageString); - } } diff --git a/formwork/src/Panel/Controllers/BackupController.php b/formwork/src/Panel/Controllers/BackupController.php index edcf1e28..323e9865 100644 --- a/formwork/src/Panel/Controllers/BackupController.php +++ b/formwork/src/Panel/Controllers/BackupController.php @@ -28,7 +28,7 @@ class BackupController extends AbstractController try { $file = $backupper->backup(); } catch (TranslatedException $e) { - return JsonResponse::error($this->translate('panel.backup.error.cannotMake', $e->getTranslatedMessage()), ResponseStatus::InternalServerError); + return JsonResponse::error($this->translate('panel.backup.error.cannotMake', $this->translate($e->getLanguageString())), ResponseStatus::InternalServerError); } $filename = basename($file); $uriName = urlencode(base64_encode($filename)); @@ -58,7 +58,7 @@ class BackupController extends AbstractController } throw new RuntimeException($this->translate('panel.backup.error.cannotDownload.invalidFilename')); } catch (TranslatedException $e) { - $this->panel->notify($this->translate('panel.backup.error.cannotDownload', $e->getTranslatedMessage()), 'error'); + $this->panel->notify($this->translate('panel.backup.error.cannotDownload', $this->translate($e->getLanguageString())), 'error'); return $this->redirectToReferer(default: $this->generateRoute('panel.tools.backups'), base: $this->panel->panelRoot()); } } @@ -81,7 +81,7 @@ class BackupController extends AbstractController } throw new RuntimeException($this->translate('panel.backup.error.cannotDelete.invalidFilename')); } catch (TranslatedException $e) { - $this->panel->notify($this->translate('panel.backup.error.cannotDelete', $e->getTranslatedMessage()), 'error'); + $this->panel->notify($this->translate('panel.backup.error.cannotDelete', $this->translate($e->getLanguageString())), 'error'); return $this->redirectToReferer(default: $this->generateRoute('panel.tools.backups'), base: $this->panel->panelRoot()); } } diff --git a/formwork/src/Panel/Controllers/PagesController.php b/formwork/src/Panel/Controllers/PagesController.php index df8643ee..8af8f346 100644 --- a/formwork/src/Panel/Controllers/PagesController.php +++ b/formwork/src/Panel/Controllers/PagesController.php @@ -83,7 +83,7 @@ class PagesController extends AbstractController $page = $this->createPage($fields); $this->panel->notify($this->translate('panel.pages.page.created'), 'success'); } catch (TranslatedException $e) { - $this->panel->notify($e->getTranslatedMessage(), 'error'); + $this->panel->notify($this->translate($e->getLanguageString()), 'error'); return $this->redirectToReferer(default: $this->generateRoute('panel.pages'), base: $this->panel->panelRoot()); } catch (InvalidValueException $e) { $identifier = $e->getIdentifier() ?? 'varMissing'; @@ -176,7 +176,7 @@ class PagesController extends AbstractController $this->panel->notify($this->translate('panel.pages.page.edited'), 'success'); } catch (TranslatedException $e) { - $this->panel->notify($e->getTranslatedMessage(), 'error'); + $this->panel->notify($this->translate($e->getLanguageString()), 'error'); } catch (InvalidValueException $e) { $identifier = $e->getIdentifier() ?? 'varMissing'; $this->panel->notify($this->translate('panel.pages.page.cannotEdit.' . $identifier), 'error'); @@ -363,7 +363,7 @@ class PagesController extends AbstractController try { $this->processPageUploads($this->request->files()->getAll(), $page); } catch (TranslatedException $e) { - $this->panel->notify($this->translate('upload.error', $e->getTranslatedMessage()), 'error'); + $this->panel->notify($this->translate('upload.error', $this->translate($e->getLanguageString())), 'error'); return $this->redirect($this->generateRoute('panel.pages.edit', ['page' => $routeParams->get('page')])); } } @@ -485,7 +485,7 @@ class PagesController extends AbstractController try { $this->processPageUploads($this->request->files()->getAll(), $page, [$page->files()->get($filename)->mimeType()], FileSystem::name($filename), true); } catch (TranslatedException $e) { - $this->panel->notify($this->translate('upload.error', $e->getTranslatedMessage()), 'error'); + $this->panel->notify($this->translate('upload.error', $this->translate($e->getLanguageString())), 'error'); return $this->redirect($this->generateRoute('panel.pages.edit', ['page' => $routeParams->get('page')])); } } diff --git a/formwork/src/Panel/Controllers/UsersController.php b/formwork/src/Panel/Controllers/UsersController.php index ce368b4a..485dc77a 100644 --- a/formwork/src/Panel/Controllers/UsersController.php +++ b/formwork/src/Panel/Controllers/UsersController.php @@ -108,7 +108,7 @@ class UsersController extends AbstractController $this->deleteUserImage($user); } } catch (TranslatedException $e) { - $this->panel->notify($e->getTranslatedMessage(), 'error'); + $this->panel->notify($this->translate($e->getLanguageString()), 'error'); return $this->redirectToReferer(default: $this->generateRoute('panel.users'), base: $this->panel->panelRoot()); } @@ -147,7 +147,7 @@ class UsersController extends AbstractController $this->panel->notify($this->translate('panel.user.image.deleted'), 'success'); } catch (TranslatedException $e) { - $this->panel->notify($e->getTranslatedMessage(), 'error'); + $this->panel->notify($this->translate($e->getLanguageString()), 'error'); } } else { $this->panel->notify($this->translate('panel.users.user.cannotEdit', $user->username()), 'error');