fix(content-docs): allow translating doc labels in sidebars.js (#7634)

This commit is contained in:
Joshua Chen 2022-06-16 22:11:21 +08:00 committed by GitHub
parent 5fe33bef06
commit 20e8e90762
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 159 additions and 6 deletions

View file

@ -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;
});
}