mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-18 18:52:23 +02:00
fix(content-docs): allow translating doc labels in sidebars.js (#7634)
This commit is contained in:
parent
5fe33bef06
commit
20e8e90762
9 changed files with 159 additions and 6 deletions
|
@ -12,6 +12,8 @@ import {
|
|||
collectSidebarCategories,
|
||||
transformSidebarItems,
|
||||
collectSidebarLinks,
|
||||
collectSidebarDocItems,
|
||||
collectSidebarRefs,
|
||||
} from './sidebars/utils';
|
||||
import type {
|
||||
LoadedVersion,
|
||||
|
@ -111,7 +113,22 @@ function getSidebarTranslationFileContent(
|
|||
]),
|
||||
);
|
||||
|
||||
return mergeTranslations([categoryContent, linksContent]);
|
||||
const docs = collectSidebarDocItems(sidebar)
|
||||
.concat(collectSidebarRefs(sidebar))
|
||||
.filter((item) => item.translatable);
|
||||
const docLinksContent: TranslationFileContent = Object.fromEntries(
|
||||
docs.map((doc) => [
|
||||
`sidebar.${sidebarName}.doc.${doc.label!}`,
|
||||
{
|
||||
message: doc.label!,
|
||||
description: `The label for the doc item ${doc.label!} in sidebar ${sidebarName}, linking to the doc ${
|
||||
doc.id
|
||||
}`,
|
||||
},
|
||||
]),
|
||||
);
|
||||
|
||||
return mergeTranslations([categoryContent, linksContent, docLinksContent]);
|
||||
}
|
||||
|
||||
function translateSidebar({
|
||||
|
@ -166,6 +183,14 @@ function translateSidebar({
|
|||
?.message ?? item.label,
|
||||
};
|
||||
}
|
||||
if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
|
||||
return {
|
||||
...item,
|
||||
label:
|
||||
sidebarsTranslations[`sidebar.${sidebarName}.doc.${item.label!}`]
|
||||
?.message ?? item.label,
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue