fix: apply translation to container tab name in getTabNameForItem#1214
fix: apply translation to container tab name in getTabNameForItem#1214bsitfeng wants to merge 1 commit into
Conversation
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.
|
Hi @bsitfeng can you adapt CHANGELOG.md ## [UNRELEASED]
### Fixed
- Container tab names are now correctly translated |
| $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()); |
There was a problem hiding this comment.
| $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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Redundant lookup: $tab_label (loop var, line 1327) already holds this same translated value from getEntries('tab', true). Reuse it instead of recomputing (extra query + hardcoded 'PluginFieldsContainer' string).
| $tabs_entries[$data['id']] = self::createTabEntry(PluginFieldsLabelTranslation::getLabelFor(array_merge($data, ['itemtype' => 'PluginFieldsContainer'])), 0, null, PluginFieldsContainer::getIcon()); | |
| $tabs_entries[$data['id']] = self::createTabEntry($tab_label, 0, null, PluginFieldsContainer::getIcon()); |
No test for getTabNameForItem(). Cover: translated label returned when a translation exists, raw label returned as fallback otherwise.
| $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()); |
There was a problem hiding this comment.
Redundant lookup: $tab_label (loop var, line 1327) already holds this same translated value from getEntries('tab', true). Reuse it instead of recomputing (extra query + hardcoded 'PluginFieldsContainer' string).
| $tabs_entries[$data['id']] = self::createTabEntry(PluginFieldsLabelTranslation::getLabelFor(array_merge($data, ['itemtype' => 'PluginFieldsContainer'])), 0, null, PluginFieldsContainer::getIcon()); | |
| $tabs_entries[$data['id']] = self::createTabEntry($tab_label, 0, null, PluginFieldsContainer::getIcon()); |
No test for getTabNameForItem(). Cover: translated label returned when a translation exists, raw label returned as fallback otherwise.
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.