From 3612f3202b67aa98d7643d2fe4f6f62abb1d63b7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Fri, 19 Apr 2024 13:09:54 +0200 Subject: [PATCH] QuickBaseForm: Replace method `translate` with trait The trait provides translatePlural method. --- application/forms/CleanupNodeForm.php | 16 +++++++++------- .../Businessprocess/Web/Form/QuickBaseForm.php | 12 +++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/application/forms/CleanupNodeForm.php b/application/forms/CleanupNodeForm.php index b4a7ad3d..cc5f1e20 100644 --- a/application/forms/CleanupNodeForm.php +++ b/application/forms/CleanupNodeForm.php @@ -56,14 +56,16 @@ public function onSuccess() $changes->deleteNode($node); } - $count = count($nodesToCleanup); - if ($count === 1) { - $successMsg = sprintf($this->translate('Successfully removed missing node %s'), $nodeName); - } else { - $successMsg = sprintf($this->translate('Successfully removed %d missing nodes'), $count); - } - $this->setSuccessMessage($successMsg); + $count = count($nodesToCleanup); + $this->setSuccessMessage(sprintf( + $this->translatePlural( + 'Successfully removed missing node %s', + 'Successfully removed %d missing nodes', + $count + ), + $count === 1 ? $nodeName : $count + )); unset($changes); diff --git a/library/Businessprocess/Web/Form/QuickBaseForm.php b/library/Businessprocess/Web/Form/QuickBaseForm.php index 36d134fd..2eb0db85 100644 --- a/library/Businessprocess/Web/Form/QuickBaseForm.php +++ b/library/Businessprocess/Web/Form/QuickBaseForm.php @@ -5,10 +5,13 @@ use Icinga\Application\Icinga; use Icinga\Application\Modules\Module; use ipl\Html\ValidHtml; +use ipl\I18n\Translation; use Zend_Form; abstract class QuickBaseForm extends Zend_Form implements ValidHtml { + use Translation; + /** * The Icinga module this form belongs to. Usually only set if the * form is initialized through the FormLoader @@ -154,13 +157,4 @@ protected function valueIsEmpty($value) return strlen($value) === 0; } - - public function translate($string) - { - if ($this->icingaModuleName === null) { - return t($string); - } else { - return mt($this->icingaModuleName, $string); - } - } }