Skip to content

fix: apply translation to container tab name in getTabNameForItem#1214

Open
bsitfeng wants to merge 1 commit into
pluginsGLPI:mainfrom
bsitfeng:container-tab-translation
Open

fix: apply translation to container tab name in getTabNameForItem#1214
bsitfeng wants to merge 1 commit into
pluginsGLPI:mainfrom
bsitfeng:container-tab-translation

Conversation

@bsitfeng

Copy link
Copy Markdown

Container tab names were displayed using $data['label'] directly without going through the translation system. This fix applies getLabelFor() to correctly display translated tab labels based on the user's language.

Fixes tab name translation not working when language is set to non-default.

Container tab names were displayed using \$data['label'] directly without
going through the translation system. This fix applies getLabelFor() to
correctly display translated tab labels based on the user's language.

Fixes tab name translation not working when language is set to non-default.
@stonebuzz stonebuzz self-requested a review June 25, 2026 06:07
@stonebuzz

stonebuzz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Hi @bsitfeng

can you adapt CHANGELOG.md

## [UNRELEASED]

### Fixed

- Container tab names are now correctly translated

Comment thread inc/container.class.php
$display_condition = new PluginFieldsContainerDisplayCondition();
if ($display_condition->computeDisplayContainer($item, $data['id'])) {
$tabs_entries[$data['id']] = self::createTabEntry($data['label'], 0, null, PluginFieldsContainer::getIcon());
$tabs_entries[$data['id']] = self::createTabEntry(PluginFieldsLabelTranslation::getLabelFor(array_merge($data, ['itemtype' => 'PluginFieldsContainer'])), 0, null, PluginFieldsContainer::getIcon());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$tabs_entries[$data['id']] = self::createTabEntry(PluginFieldsLabelTranslation::getLabelFor(array_merge($data, ['itemtype' => 'PluginFieldsContainer'])), 0, null, PluginFieldsContainer::getIcon());
$label = PluginFieldsLabelTranslation::getLabelFor(
array_merge($data, ['itemtype' => PluginFieldsContainer::class])
);
$tabs_entries[$data['id']] = self::createTabEntry($label, 0, null, PluginFieldsContainer::getIcon());

improves readability

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getTabNameForItem has no test in tests/Units/. Can you add a test case where a container has a translation for the active session language and verify the translated label is returned, and another where no translation exists and the raw label value is returned as fallback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants