From d65f68db17674be0a286ff75c19d67094ad26293 Mon Sep 17 00:00:00 2001 From: raviks789 Date: Mon, 14 Oct 2024 12:32:28 +0200 Subject: [PATCH] Insert trait `Translation` in parent class `StateListItem` instead of `RedundancyGroupListItem` --- .../Widget/ItemList/RedundancyGroupListItem.php | 2 -- .../Icingadb/Widget/ItemList/StateListItem.php | 15 +++++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php index c9519baf9..302be9df4 100644 --- a/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php +++ b/library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php @@ -14,7 +14,6 @@ use Icinga\Module\Icingadb\Widget\PluginOutputContainer; use Icinga\Module\Icingadb\Widget\DependencyNodeStatistics; use ipl\Html\BaseHtmlElement; -use ipl\I18n\Translation; use ipl\Sql\Expression; use ipl\Stdlib\Filter; use ipl\Web\Widget\StateBall; @@ -33,7 +32,6 @@ class RedundancyGroupListItem extends StateListItem use ListItemCommonLayout; use Auth; use Database; - use Translation; protected $defaultAttributes = ['class' => ['list-item', 'redundancy-group-list-item']]; diff --git a/library/Icingadb/Widget/ItemList/StateListItem.php b/library/Icingadb/Widget/ItemList/StateListItem.php index c143b7ac4..f454c5292 100644 --- a/library/Icingadb/Widget/ItemList/StateListItem.php +++ b/library/Icingadb/Widget/ItemList/StateListItem.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Widget\IconImage; use Icinga\Module\Icingadb\Widget\PluginOutputContainer; use ipl\Html\HtmlElement; +use ipl\I18n\Translation; use ipl\Web\Common\BaseListItem; use ipl\Web\Widget\EmptyState; use ipl\Web\Widget\StateBadge; @@ -26,6 +27,8 @@ */ abstract class StateListItem extends BaseListItem { + use Translation; + /** @var StateList The list where the item is part of */ protected $list; @@ -66,10 +69,10 @@ protected function createIconImage(): ?BaseHtmlElement protected function assembleCaption(BaseHtmlElement $caption): void { if ($this->state->soft_state === null && $this->state->output === null) { - $caption->addHtml(Text::create(t('Waiting for Icinga DB to synchronize the state.'))); + $caption->addHtml(Text::create($this->translate('Waiting for Icinga DB to synchronize the state.'))); } else { if (empty($this->state->output)) { - $pluginOutput = new EmptyState(t('Output unavailable.')); + $pluginOutput = new EmptyState($this->translate('Output unavailable.')); } else { $pluginOutput = new PluginOutputContainer(PluginOutput::fromObject($this->item)); } @@ -90,7 +93,7 @@ protected function assembleIconImage(BaseHtmlElement $iconImage): void protected function assembleTitle(BaseHtmlElement $title): void { $title->addHtml(Html::sprintf( - t('%s is %s', ' is '), + $this->translate('%s is %s', ' is '), $this->createSubject(), Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated()) )); @@ -100,9 +103,9 @@ protected function assembleTitle(BaseHtmlElement $title): void if ($total > 1000) { $total = '1000+'; - $tooltip = t('Up to 1000+ affected objects'); + $tooltip = $this->translate('Up to 1000+ affected objects'); } else { - $tooltip = sprintf(tp('%d affected object', 'Up to %d affected objects', $total)); + $tooltip = sprintf($this->translatePlural('%d affected object', 'Up to %d affected objects', $total)); } $icon = new Icon(Icons::UNREACHABLE); @@ -136,7 +139,7 @@ protected function createTimestamp(): ?BaseHtmlElement $since = null; if ($this->state->is_overdue) { $since = new TimeSince($this->state->next_update->getTimestamp()); - $since->prepend(t('Overdue') . ' '); + $since->prepend($this->translate('Overdue') . ' '); $since->prependHtml(new Icon(Icons::WARNING)); } elseif ($this->state->last_state_change !== null && $this->state->last_state_change->getTimestamp() > 0) { $since = new TimeSince($this->state->last_state_change->getTimestamp());