Skip to content

Commit

Permalink
navbar dropdown subitems should be translated properly
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jan 28, 2021
1 parent 671748f commit 6bd2f51
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
19 changes: 14 additions & 5 deletions packages/docusaurus-theme-classic/src/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}),
};
}

Expand Down

0 comments on commit 6bd2f51

Please sign in to comment.