Skip to content

Commit

Permalink
Insert trait Translation in parent class StateListItem instead of…
Browse files Browse the repository at this point in the history
… `RedundancyGroupListItem`
  • Loading branch information
raviks789 committed Oct 14, 2024
1 parent 7343c8d commit 1e7e7fd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
14 changes: 14 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
StateListItem: Use `Translator::translatePlural()` to translate affected objects tooltip
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch root-problem-list
# Your branch is ahead of 'origin/root-problem-list' by 1 commit.
# (use "git push" to publish your local commits)
#
# Changes to be committed:
# modified: library/Icingadb/Widget/ItemList/StateListItem.php
#
# Changes not staged for commit:
# modified: library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
#
2 changes: 0 additions & 2 deletions library/Icingadb/Widget/ItemList/RedundancyGroupListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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']];

Expand Down
15 changes: 9 additions & 6 deletions library/Icingadb/Widget/ItemList/StateListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,8 @@
*/
abstract class StateListItem extends BaseListItem
{
use Translation;

/** @var StateList The list where the item is part of */
protected $list;

Expand Down Expand Up @@ -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));
}
Expand All @@ -90,7 +93,7 @@ protected function assembleIconImage(BaseHtmlElement $iconImage): void
protected function assembleTitle(BaseHtmlElement $title): void
{
$title->addHtml(Html::sprintf(
t('%s is %s', '<hostname> is <state-text>'),
$this->translate('%s is %s', '<hostname> is <state-text>'),
$this->createSubject(),
Html::tag('span', ['class' => 'state-text'], $this->state->getStateTextTranslated())
));
Expand All @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 1e7e7fd

Please sign in to comment.