mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-08 14:47:12 +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",
|
||||
"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)",
|
||||
|
|
|
@ -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: {
|
||||
|
|
|
@ -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),
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue