mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-09 15:17:23 +02:00
fix(v2): navbar dropdown subitems should be translated properly(#4118)
This commit is contained in:
parent
671748f065
commit
3031c47c3b
3 changed files with 30 additions and 7 deletions
|
@ -12,6 +12,10 @@ Array [
|
||||||
"description": "Navbar item with label Dropdown item 1",
|
"description": "Navbar item with label Dropdown item 1",
|
||||||
"message": "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 {
|
"title": Object {
|
||||||
"description": "The title in the navbar",
|
"description": "The title in the navbar",
|
||||||
"message": "navbar title",
|
"message": "navbar title",
|
||||||
|
@ -94,7 +98,11 @@ Object {
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"items": Array [],
|
"items": Array [],
|
||||||
"label": "Dropdown item 1",
|
"label": "Dropdown item 1 (translated)",
|
||||||
|
},
|
||||||
|
Object {
|
||||||
|
"items": Array [],
|
||||||
|
"label": "Dropdown item 2 (translated)",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"label": "Dropdown (translated)",
|
"label": "Dropdown (translated)",
|
||||||
|
|
|
@ -22,7 +22,13 @@ const ThemeConfigSample: ThemeConfig = {
|
||||||
style: 'dark',
|
style: 'dark',
|
||||||
hideOnScroll: false,
|
hideOnScroll: false,
|
||||||
items: [
|
items: [
|
||||||
{label: 'Dropdown', items: [{label: 'Dropdown item 1', items: []}]},
|
{
|
||||||
|
label: 'Dropdown',
|
||||||
|
items: [
|
||||||
|
{label: 'Dropdown item 1', items: []},
|
||||||
|
{label: 'Dropdown item 2', items: []},
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
|
|
|
@ -54,11 +54,20 @@ function translateNavbar(
|
||||||
...navbar,
|
...navbar,
|
||||||
title: navbarTranslations.title?.message ?? navbar.title,
|
title: navbarTranslations.title?.message ?? navbar.title,
|
||||||
// TODO handle properly all the navbar item types here!
|
// TODO handle properly all the navbar item types here!
|
||||||
items: navbar.items.map((item) => ({
|
items: navbar.items.map((item) => {
|
||||||
...item,
|
const subItems = item.items?.map((subItem) => ({
|
||||||
label:
|
...subItem,
|
||||||
navbarTranslations[`item.label.${item.label}`]?.message ?? item.label,
|
label:
|
||||||
})),
|
navbarTranslations[`item.label.${subItem.label}`]?.message ??
|
||||||
|
subItem.label,
|
||||||
|
}));
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
label:
|
||||||
|
navbarTranslations[`item.label.${item.label}`]?.message ?? item.label,
|
||||||
|
...(subItems ? {items: subItems} : undefined),
|
||||||
|
};
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue