fix(v2): navbar dropdown subitems should be translated properly(#4118)

This commit is contained in:
Sébastien Lorber 2021-01-28 18:22:36 +01:00 committed by GitHub
parent 671748f065
commit 3031c47c3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 7 deletions

View file

@ -12,6 +12,10 @@ Array [
"description": "Navbar item with label Dropdown item 1",
"message": "Dropdown item 1",
},
"item.label.Dropdown item 2": Object {
"description": "Navbar item with label Dropdown item 2",
"message": "Dropdown item 2",
},
"title": Object {
"description": "The title in the navbar",
"message": "navbar title",
@ -94,7 +98,11 @@ Object {
"items": Array [
Object {
"items": Array [],
"label": "Dropdown item 1",
"label": "Dropdown item 1 (translated)",
},
Object {
"items": Array [],
"label": "Dropdown item 2 (translated)",
},
],
"label": "Dropdown (translated)",

View file

@ -22,7 +22,13 @@ const ThemeConfigSample: ThemeConfig = {
style: 'dark',
hideOnScroll: false,
items: [
{label: 'Dropdown', items: [{label: 'Dropdown item 1', items: []}]},
{
label: 'Dropdown',
items: [
{label: 'Dropdown item 1', items: []},
{label: 'Dropdown item 2', items: []},
],
},
],
},
footer: {

View file

@ -54,11 +54,20 @@ function translateNavbar(
...navbar,
title: navbarTranslations.title?.message ?? navbar.title,
// TODO handle properly all the navbar item types here!
items: navbar.items.map((item) => ({
...item,
label:
navbarTranslations[`item.label.${item.label}`]?.message ?? item.label,
})),
items: navbar.items.map((item) => {
const subItems = item.items?.map((subItem) => ({
...subItem,
label:
navbarTranslations[`item.label.${subItem.label}`]?.message ??
subItem.label,
}));
return {
...item,
label:
navbarTranslations[`item.label.${item.label}`]?.message ?? item.label,
...(subItems ? {items: subItems} : undefined),
};
}),
};
}