diff --git a/jest.config.mjs b/jest.config.mjs index ca2be525b050..3d6ac4dfca18 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -34,7 +34,7 @@ export default { verbose: true, // Default 5s timeout often fails on Windows :s, // see https://github.com/facebook/docusaurus/pull/8259 - testTimeout: 15000, + testTimeout: 25000, setupFiles: ['./jest/setup.ts'], testEnvironmentOptions: { url: 'https://docusaurus.io/', diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/translations.test.ts.snap b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/translations.test.ts.snap index 82dedb7cbeb0..8d5f668a1b26 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/translations.test.ts.snap +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/__snapshots__/translations.test.ts.snap @@ -24,6 +24,18 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, + "sidebar.otherSidebar.category.cat-with-key": { + "description": "The label for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.description": { + "description": "The generated-index page description for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index description", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.title": { + "description": "The generated-index page title for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index title", + }, "sidebar.otherSidebar.doc.Fifth doc translatable": { "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", @@ -57,6 +69,18 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, + "sidebar.otherSidebar.category.cat-with-key": { + "description": "The label for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.description": { + "description": "The generated-index page description for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index description", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.title": { + "description": "The generated-index page title for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index title", + }, "sidebar.otherSidebar.doc.Fifth doc translatable": { "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", @@ -90,6 +114,18 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, + "sidebar.otherSidebar.category.cat-with-key": { + "description": "The label for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.description": { + "description": "The generated-index page description for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index description", + }, + "sidebar.otherSidebar.category.cat-with-key.link.generated-index.title": { + "description": "The generated-index page title for category 'Category with key' in sidebar 'otherSidebar'", + "message": "Category with key - index title", + }, "sidebar.otherSidebar.doc.Fifth doc translatable": { "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", @@ -273,6 +309,21 @@ exports[`translateLoadedContent returns translated loaded content 1`] = ` "translatable": true, "type": "ref", }, + { + "collapsed": false, + "collapsible": true, + "items": [], + "key": "cat-with-key", + "label": "Category with key (translated)", + "link": { + "description": "Category with key - index description (translated)", + "permalink": "/docs/category/cat-with-key", + "slug": "/category/cat-with-key-slug", + "title": "Category with key - index title (translated)", + "type": "generated-index", + }, + "type": "category", + }, ], }, "tagsPath": "/tags/", @@ -444,6 +495,21 @@ exports[`translateLoadedContent returns translated loaded content 1`] = ` "translatable": true, "type": "ref", }, + { + "collapsed": false, + "collapsible": true, + "items": [], + "key": "cat-with-key", + "label": "Category with key (translated)", + "link": { + "description": "Category with key - index description (translated)", + "permalink": "/docs/category/cat-with-key", + "slug": "/category/cat-with-key-slug", + "title": "Category with key - index title (translated)", + "type": "generated-index", + }, + "type": "category", + }, ], }, "tagsPath": "/tags/", @@ -615,6 +681,21 @@ exports[`translateLoadedContent returns translated loaded content 1`] = ` "translatable": true, "type": "ref", }, + { + "collapsed": false, + "collapsible": true, + "items": [], + "key": "cat-with-key", + "label": "Category with key (translated)", + "link": { + "description": "Category with key - index description (translated)", + "permalink": "/docs/category/cat-with-key", + "slug": "/category/cat-with-key-slug", + "title": "Category with key - index title (translated)", + "type": "generated-index", + }, + "type": "category", + }, ], }, "tagsPath": "/tags/", diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts index 26666037c589..87485078fad5 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts @@ -116,6 +116,21 @@ function createSampleVersion( label: 'Fifth doc translatable', translatable: true, }, + { + type: 'category', + key: 'cat-with-key', + label: 'Category with key', + collapsed: false, + collapsible: true, + link: { + type: 'generated-index', + slug: '/category/cat-with-key-slug', + permalink: '/docs/category/cat-with-key', + title: 'Category with key - index title', + description: 'Category with key - index description', + }, + items: [], + }, ], }, ...version, diff --git a/packages/docusaurus-plugin-content-docs/src/translations.ts b/packages/docusaurus-plugin-content-docs/src/translations.ts index 9ad1a148b039..ecea3252d438 100644 --- a/packages/docusaurus-plugin-content-docs/src/translations.ts +++ b/packages/docusaurus-plugin-content-docs/src/translations.ts @@ -177,13 +177,14 @@ function translateSidebar({ return undefined; } if (category.link.type === 'generated-index') { + const categoryKey = category.key ?? category.label; const title = sidebarsTranslations[ - `sidebar.${sidebarName}.category.${category.label}.link.generated-index.title` + `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title` ]?.message ?? category.link.title; const description = sidebarsTranslations[ - `sidebar.${sidebarName}.category.${category.label}.link.generated-index.description` + `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description` ]?.message ?? category.link.description; return { ...category.link,