From 66c80fc799e90d2cf767bbf3d176de7b810227d5 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 17 Oct 2025 11:53:53 +0200 Subject: [PATCH] Slightly improve translation error message formatting --- .../__snapshots__/translations.test.ts.snap | 36 +++++++++---------- .../src/__tests__/translations.test.ts | 32 ++++++++--------- .../src/translations.ts | 10 +++--- 3 files changed, 39 insertions(+), 39 deletions(-) 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 7498d1ba22..1c0b64d149 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 @@ -5,27 +5,27 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` { "content": { "sidebar.docs.category.Getting started": { - "description": "The label for category Getting started in sidebar docs", + "description": "The label for category 'Getting started' in sidebar 'docs'", "message": "Getting started", }, "sidebar.docs.category.Getting started.link.generated-index.description": { - "description": "The generated-index page description for category Getting started in sidebar docs", + "description": "The generated-index page description for category 'Getting started' in sidebar 'docs'", "message": "Getting started index description", }, "sidebar.docs.category.Getting started.link.generated-index.title": { - "description": "The generated-index page title for category Getting started in sidebar docs", + "description": "The generated-index page title for category 'Getting started' in sidebar 'docs'", "message": "Getting started index title", }, "sidebar.docs.doc.Second doc translatable": { - "description": "The label for the doc item Second doc translatable in sidebar docs, linking to the doc doc2", + "description": "The label for the doc item 'Second doc translatable' in sidebar 'docs', linking to the doc doc2", "message": "Second doc translatable", }, "sidebar.docs.link.Link label": { - "description": "The label for link Link label in sidebar docs, linking to https://facebook.com", + "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, "sidebar.otherSidebar.doc.Fifth doc translatable": { - "description": "The label for the doc item Fifth doc translatable in sidebar otherSidebar, linking to the doc doc5", + "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", }, "version.label": { @@ -38,27 +38,27 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` { "content": { "sidebar.docs.category.Getting started": { - "description": "The label for category Getting started in sidebar docs", + "description": "The label for category 'Getting started' in sidebar 'docs'", "message": "Getting started", }, "sidebar.docs.category.Getting started.link.generated-index.description": { - "description": "The generated-index page description for category Getting started in sidebar docs", + "description": "The generated-index page description for category 'Getting started' in sidebar 'docs'", "message": "Getting started index description", }, "sidebar.docs.category.Getting started.link.generated-index.title": { - "description": "The generated-index page title for category Getting started in sidebar docs", + "description": "The generated-index page title for category 'Getting started' in sidebar 'docs'", "message": "Getting started index title", }, "sidebar.docs.doc.Second doc translatable": { - "description": "The label for the doc item Second doc translatable in sidebar docs, linking to the doc doc2", + "description": "The label for the doc item 'Second doc translatable' in sidebar 'docs', linking to the doc doc2", "message": "Second doc translatable", }, "sidebar.docs.link.Link label": { - "description": "The label for link Link label in sidebar docs, linking to https://facebook.com", + "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, "sidebar.otherSidebar.doc.Fifth doc translatable": { - "description": "The label for the doc item Fifth doc translatable in sidebar otherSidebar, linking to the doc doc5", + "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", }, "version.label": { @@ -71,27 +71,27 @@ exports[`getLoadedContentTranslationFiles returns translation files 1`] = ` { "content": { "sidebar.docs.category.Getting started": { - "description": "The label for category Getting started in sidebar docs", + "description": "The label for category 'Getting started' in sidebar 'docs'", "message": "Getting started", }, "sidebar.docs.category.Getting started.link.generated-index.description": { - "description": "The generated-index page description for category Getting started in sidebar docs", + "description": "The generated-index page description for category 'Getting started' in sidebar 'docs'", "message": "Getting started index description", }, "sidebar.docs.category.Getting started.link.generated-index.title": { - "description": "The generated-index page title for category Getting started in sidebar docs", + "description": "The generated-index page title for category 'Getting started' in sidebar 'docs'", "message": "Getting started index title", }, "sidebar.docs.doc.Second doc translatable": { - "description": "The label for the doc item Second doc translatable in sidebar docs, linking to the doc doc2", + "description": "The label for the doc item 'Second doc translatable' in sidebar 'docs', linking to the doc doc2", "message": "Second doc translatable", }, "sidebar.docs.link.Link label": { - "description": "The label for link Link label in sidebar docs, linking to https://facebook.com", + "description": "The label for link 'Link label' in sidebar 'docs', linking to 'https://facebook.com'", "message": "Link label", }, "sidebar.otherSidebar.doc.Fifth doc translatable": { - "description": "The label for the doc item Fifth doc translatable in sidebar otherSidebar, linking to the doc doc5", + "description": "The label for the doc item 'Fifth doc translatable' in sidebar 'otherSidebar', linking to the doc doc5", "message": "Fifth doc translatable", }, "version.label": { 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 f0bcbdd582..26666037c5 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/translations.test.ts @@ -232,35 +232,35 @@ describe('getLoadedContentTranslationFiles', () => { { "content": { "sidebar.sidebarWithConflicts.category.key-cat1": { - "description": "The label for category COMMON LABEL in sidebar sidebarWithConflicts", + "description": "The label for category 'COMMON LABEL' in sidebar 'sidebarWithConflicts'", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.category.key-cat2": { - "description": "The label for category COMMON LABEL in sidebar sidebarWithConflicts", + "description": "The label for category 'COMMON LABEL' in sidebar 'sidebarWithConflicts'", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.doc.key-doc4": { - "description": "The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc4", + "description": "The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc4", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.doc.key-doc5": { - "description": "The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc5", + "description": "The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc5", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.doc.key-ref4": { - "description": "The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc4", + "description": "The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc4", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.doc.key-ref5": { - "description": "The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc5", + "description": "The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc5", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.link.key-link1": { - "description": "The label for link COMMON LABEL in sidebar sidebarWithConflicts, linking to https://example.com", + "description": "The label for link 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to 'https://example.com'", "message": "COMMON LABEL", }, "sidebar.sidebarWithConflicts.link.key-link2": { - "description": "The label for link COMMON LABEL in sidebar sidebarWithConflicts, linking to https://example.com", + "description": "The label for link 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to 'https://example.com'", "message": "COMMON LABEL", }, "version.label": { @@ -279,18 +279,18 @@ describe('getLoadedContentTranslationFiles', () => { .toThrowErrorMatchingInlineSnapshot(` "Multiple docs sidebar items produce the same translation key. - \`sidebar.sidebarWithConflicts.category.COMMON LABEL\`: 2 duplicates found: - - COMMON LABEL (The label for category COMMON LABEL in sidebar sidebarWithConflicts) - - COMMON LABEL (The label for category COMMON LABEL in sidebar sidebarWithConflicts) + - COMMON LABEL (The label for category 'COMMON LABEL' in sidebar 'sidebarWithConflicts') + - COMMON LABEL (The label for category 'COMMON LABEL' in sidebar 'sidebarWithConflicts') - \`sidebar.sidebarWithConflicts.link.COMMON LABEL\`: 2 duplicates found: - - COMMON LABEL (The label for link COMMON LABEL in sidebar sidebarWithConflicts, linking to https://example.com) - - COMMON LABEL (The label for link COMMON LABEL in sidebar sidebarWithConflicts, linking to https://example.com) + - COMMON LABEL (The label for link 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to 'https://example.com') + - COMMON LABEL (The label for link 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to 'https://example.com') - \`sidebar.sidebarWithConflicts.doc.COMMON LABEL\`: 4 duplicates found: - - COMMON LABEL (The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc4) - - COMMON LABEL (The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc5) - - COMMON LABEL (The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc4) - - COMMON LABEL (The label for the doc item COMMON LABEL in sidebar sidebarWithConflicts, linking to the doc doc5) + - COMMON LABEL (The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc4) + - COMMON LABEL (The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc5) + - COMMON LABEL (The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc4) + - COMMON LABEL (The label for the doc item 'COMMON LABEL' in sidebar 'sidebarWithConflicts', linking to the doc doc5) To avoid translation key conflicts, use the \`key\` attribute on the sidebar items above to uniquely identify them. diff --git a/packages/docusaurus-plugin-content-docs/src/translations.ts b/packages/docusaurus-plugin-content-docs/src/translations.ts index f7e10af755..9ad1a148b0 100644 --- a/packages/docusaurus-plugin-content-docs/src/translations.ts +++ b/packages/docusaurus-plugin-content-docs/src/translations.ts @@ -99,7 +99,7 @@ function getSidebarTranslationFileContent( `sidebar.${sidebarName}.category.${categoryKey}`, { message: category.label, - description: `The label for category ${category.label} in sidebar ${sidebarName}`, + description: `The label for category '${category.label}' in sidebar '${sidebarName}'`, }, ]); @@ -109,7 +109,7 @@ function getSidebarTranslationFileContent( `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.title`, { message: category.link.title, - description: `The generated-index page title for category ${category.label} in sidebar ${sidebarName}`, + description: `The generated-index page title for category '${category.label}' in sidebar '${sidebarName}'`, }, ]); } @@ -118,7 +118,7 @@ function getSidebarTranslationFileContent( `sidebar.${sidebarName}.category.${categoryKey}.link.generated-index.description`, { message: category.link.description, - description: `The generated-index page description for category ${category.label} in sidebar ${sidebarName}`, + description: `The generated-index page description for category '${category.label}' in sidebar '${sidebarName}'`, }, ]); } @@ -135,7 +135,7 @@ function getSidebarTranslationFileContent( `sidebar.${sidebarName}.link.${linkKey}`, { message: link.label, - description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`, + description: `The label for link '${link.label}' in sidebar '${sidebarName}', linking to '${link.href}'`, }, ]; }); @@ -149,7 +149,7 @@ function getSidebarTranslationFileContent( `sidebar.${sidebarName}.doc.${docKey}`, { message: doc.label!, - description: `The label for the doc item ${doc.label!} in sidebar ${sidebarName}, linking to the doc ${ + description: `The label for the doc item '${doc.label!}' in sidebar '${sidebarName}', linking to the doc ${ doc.id }`, },