feat(admin-*,dashboard): i18n labels for menu item extensions (#13843)

* i18n menu item labels

* changeset

* changeset
This commit is contained in:
Leonardo Benini
2025-11-06 13:42:32 +01:00
committed by GitHub
parent 3095b63784
commit 3852efbcff
8 changed files with 104 additions and 9 deletions

View File

@@ -348,6 +348,7 @@ const ExtensionRouteSection = () => {
label={item.label}
icon={item.icon ? item.icon : <SquaresPlus />}
items={item.items}
translationNs={item.translationNs}
type="extension"
/>
)

View File

@@ -17,6 +17,7 @@ type ItemType = "core" | "extension" | "setting"
type NestedItemProps = {
label: string
to: string
translationNs?: string
}
export type INavItem = {
@@ -27,6 +28,7 @@ export type INavItem = {
type?: ItemType
from?: string
nested?: string
translationNs?: string
}
const BASE_NAV_LINK_CLASSES =
@@ -90,10 +92,15 @@ export const NavItem = ({
items,
type = "core",
from,
translationNs,
}: INavItem) => {
const { t } = useTranslation(translationNs as any)
const { pathname } = useLocation()
const [open, setOpen] = useState(getIsOpen(to, items, pathname))
// Use translation if translationNs is provided, otherwise use label as-is
const displayLabel: string = translationNs ? t(label) : label
useEffect(() => {
setOpen(getIsOpen(to, items, pathname))
}, [pathname, to, items])
@@ -150,7 +157,7 @@ export const NavItem = ({
</div>
)}
<Text size="small" weight="plus" leading="compact">
{label}
{displayLabel}
</Text>
</NavLink>
</NavItemTooltip>
@@ -166,7 +173,7 @@ export const NavItem = ({
<Icon icon={icon} type={type} />
</div>
<Text size="small" weight="plus" leading="compact">
{label}
{displayLabel}
</Text>
</RadixCollapsible.Trigger>
<RadixCollapsible.Content>
@@ -189,12 +196,15 @@ export const NavItem = ({
}}
>
<Text size="small" weight="plus" leading="compact">
{label}
{displayLabel}
</Text>
</NavLink>
</NavItemTooltip>
</li>
{items.map((item) => {
const { t: itemT } = useTranslation(item.translationNs as any)
const itemLabel: string = item.translationNs ? itemT(item.label) : item.label
return (
<li key={item.to} className="flex h-7 items-center">
<NavItemTooltip to={item.to}>
@@ -213,7 +223,7 @@ export const NavItem = ({
}}
>
<Text size="small" weight="plus" leading="compact">
{item.label}
{itemLabel}
</Text>
</NavLink>
</NavItemTooltip>

View File

@@ -187,6 +187,7 @@ export class DashboardApp {
icon: item.icon ? <item.icon /> : undefined,
items: [],
nested: item.nested,
translationNs: item.translationNs,
}
if (parentPath !== "/" && tempRegistry[parentPath]) {

View File

@@ -24,6 +24,7 @@ export type MenuItemExtension = {
path: string
icon?: ComponentType
nested?: NestedRoutePosition
translationNs?: string
}
export type WidgetExtension = {