@docusaurus/plugin-content-docs 0.0.0-5124 → 0.0.0-5128

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,6 +30,10 @@ function normalizeItem(item) {
30
30
  // This will never throw anyways
31
31
  return normalizeSidebar(item, 'sidebar items slice');
32
32
  }
33
+ if ((item.type === 'doc' || item.type === 'ref') &&
34
+ typeof item.label === 'string') {
35
+ return [{ ...item, translatable: true }];
36
+ }
33
37
  if (item.type === 'category') {
34
38
  const normalizedCategory = {
35
39
  ...item,
@@ -22,6 +22,11 @@ export declare type SidebarItemDoc = SidebarItemBase & {
22
22
  type: 'doc' | 'ref';
23
23
  label?: string;
24
24
  id: string;
25
+ /**
26
+ * This is an internal marker. Items with labels defined in the config needs
27
+ * to be translated with JSON
28
+ */
29
+ translatable?: true;
25
30
  };
26
31
  export declare type SidebarItemHtml = SidebarItemBase & {
27
32
  type: 'html';
@@ -73,7 +78,7 @@ export declare type SidebarItemCategoryConfig = Expand<Optional<SidebarItemCateg
73
78
  export declare type SidebarCategoriesShorthand = {
74
79
  [sidebarCategory: string]: SidebarCategoriesShorthand | SidebarItemConfig[];
75
80
  };
76
- export declare type SidebarItemConfig = SidebarItemDoc | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
81
+ export declare type SidebarItemConfig = Omit<SidebarItemDoc, 'translatable'> | SidebarItemHtml | SidebarItemLink | SidebarItemAutogenerated | SidebarItemCategoryConfig | string | SidebarCategoriesShorthand;
77
82
  export declare type SidebarConfig = SidebarCategoriesShorthand | SidebarItemConfig[];
78
83
  export declare type SidebarsConfig = {
79
84
  [sidebarId: string]: SidebarConfig;
@@ -11,6 +11,7 @@ export declare function transformSidebarItems(sidebar: Sidebar, updateFn: (item:
11
11
  export declare function collectSidebarDocItems(sidebar: Sidebar): SidebarItemDoc[];
12
12
  export declare function collectSidebarCategories(sidebar: Sidebar): SidebarItemCategory[];
13
13
  export declare function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[];
14
+ export declare function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[];
14
15
  export declare function collectSidebarDocIds(sidebar: Sidebar): string[];
15
16
  export declare function collectSidebarNavigation(sidebar: Sidebar): SidebarNavigationItem[];
16
17
  export declare function collectSidebarsDocIds(sidebars: Sidebars): {
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
9
+ exports.toNavigationLink = exports.toDocNavigationLink = exports.createSidebarsUtils = exports.collectSidebarsNavigations = exports.collectSidebarsDocIds = exports.collectSidebarNavigation = exports.collectSidebarDocIds = exports.collectSidebarRefs = exports.collectSidebarLinks = exports.collectSidebarCategories = exports.collectSidebarDocItems = exports.transformSidebarItems = exports.isCategoriesShorthand = void 0;
10
10
  const tslib_1 = require("tslib");
11
11
  const lodash_1 = tslib_1.__importDefault(require("lodash"));
12
12
  const utils_1 = require("@docusaurus/utils");
@@ -55,6 +55,10 @@ function collectSidebarLinks(sidebar) {
55
55
  return collectSidebarItemsOfType('link', sidebar);
56
56
  }
57
57
  exports.collectSidebarLinks = collectSidebarLinks;
58
+ function collectSidebarRefs(sidebar) {
59
+ return collectSidebarItemsOfType('ref', sidebar);
60
+ }
61
+ exports.collectSidebarRefs = collectSidebarRefs;
58
62
  // /!\ docId order matters for navigation!
59
63
  function collectSidebarDocIds(sidebar) {
60
64
  return flattenSidebarItems(sidebar).flatMap((item) => {
@@ -26,6 +26,7 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append({
26
26
  type: utils_validation_1.Joi.string().valid('doc', 'ref').required(),
27
27
  id: utils_validation_1.Joi.string().required(),
28
28
  label: utils_validation_1.Joi.string(),
29
+ translatable: utils_validation_1.Joi.boolean(),
29
30
  });
30
31
  const sidebarItemHtmlSchema = sidebarItemBaseSchema.append({
31
32
  type: 'html',
@@ -71,7 +71,17 @@ function getSidebarTranslationFileContent(sidebar, sidebarName) {
71
71
  description: `The label for link ${link.label} in sidebar ${sidebarName}, linking to ${link.href}`,
72
72
  },
73
73
  ]));
74
- return (0, utils_1.mergeTranslations)([categoryContent, linksContent]);
74
+ const docs = (0, utils_2.collectSidebarDocItems)(sidebar)
75
+ .concat((0, utils_2.collectSidebarRefs)(sidebar))
76
+ .filter((item) => item.translatable);
77
+ const docLinksContent = Object.fromEntries(docs.map((doc) => [
78
+ `sidebar.${sidebarName}.doc.${doc.label}`,
79
+ {
80
+ message: doc.label,
81
+ description: `The label for the doc item ${doc.label} in sidebar ${sidebarName}, linking to the doc ${doc.id}`,
82
+ },
83
+ ]));
84
+ return (0, utils_1.mergeTranslations)([categoryContent, linksContent, docLinksContent]);
75
85
  }
76
86
  function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
77
87
  function transformSidebarCategoryLink(category) {
@@ -106,6 +116,13 @@ function translateSidebar({ sidebar, sidebarName, sidebarsTranslations, }) {
106
116
  ?.message ?? item.label,
107
117
  };
108
118
  }
119
+ if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
120
+ return {
121
+ ...item,
122
+ label: sidebarsTranslations[`sidebar.${sidebarName}.doc.${item.label}`]
123
+ ?.message ?? item.label,
124
+ };
125
+ }
109
126
  return item;
110
127
  });
111
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/plugin-content-docs",
3
- "version": "0.0.0-5124",
3
+ "version": "0.0.0-5128",
4
4
  "description": "Docs plugin for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,
@@ -34,13 +34,13 @@
34
34
  },
35
35
  "license": "MIT",
36
36
  "dependencies": {
37
- "@docusaurus/core": "0.0.0-5124",
38
- "@docusaurus/logger": "0.0.0-5124",
39
- "@docusaurus/mdx-loader": "0.0.0-5124",
40
- "@docusaurus/module-type-aliases": "0.0.0-5124",
41
- "@docusaurus/types": "0.0.0-5124",
42
- "@docusaurus/utils": "0.0.0-5124",
43
- "@docusaurus/utils-validation": "0.0.0-5124",
37
+ "@docusaurus/core": "0.0.0-5128",
38
+ "@docusaurus/logger": "0.0.0-5128",
39
+ "@docusaurus/mdx-loader": "0.0.0-5128",
40
+ "@docusaurus/module-type-aliases": "0.0.0-5128",
41
+ "@docusaurus/types": "0.0.0-5128",
42
+ "@docusaurus/utils": "0.0.0-5128",
43
+ "@docusaurus/utils-validation": "0.0.0-5128",
44
44
  "@types/react-router-config": "^5.0.6",
45
45
  "combine-promises": "^1.1.0",
46
46
  "fs-extra": "^10.1.0",
@@ -67,5 +67,5 @@
67
67
  "engines": {
68
68
  "node": ">=16.14"
69
69
  },
70
- "gitHead": "dba5e8d5a7bc07b946888664f9cc3f07564093e1"
70
+ "gitHead": "19486110d408838f8244019b7909fc02a7b2bdfd"
71
71
  }
@@ -44,6 +44,12 @@ export function normalizeItem(
44
44
  // This will never throw anyways
45
45
  return normalizeSidebar(item, 'sidebar items slice');
46
46
  }
47
+ if (
48
+ (item.type === 'doc' || item.type === 'ref') &&
49
+ typeof item.label === 'string'
50
+ ) {
51
+ return [{...item, translatable: true}];
52
+ }
47
53
  if (item.type === 'category') {
48
54
  const normalizedCategory: NormalizedSidebarItemCategory = {
49
55
  ...item,
@@ -27,6 +27,11 @@ export type SidebarItemDoc = SidebarItemBase & {
27
27
  type: 'doc' | 'ref';
28
28
  label?: string;
29
29
  id: string;
30
+ /**
31
+ * This is an internal marker. Items with labels defined in the config needs
32
+ * to be translated with JSON
33
+ */
34
+ translatable?: true;
30
35
  };
31
36
 
32
37
  export type SidebarItemHtml = SidebarItemBase & {
@@ -94,7 +99,7 @@ export type SidebarCategoriesShorthand = {
94
99
  };
95
100
 
96
101
  export type SidebarItemConfig =
97
- | SidebarItemDoc
102
+ | Omit<SidebarItemDoc, 'translatable'>
98
103
  | SidebarItemHtml
99
104
  | SidebarItemLink
100
105
  | SidebarItemAutogenerated
@@ -81,6 +81,9 @@ export function collectSidebarCategories(
81
81
  export function collectSidebarLinks(sidebar: Sidebar): SidebarItemLink[] {
82
82
  return collectSidebarItemsOfType('link', sidebar);
83
83
  }
84
+ export function collectSidebarRefs(sidebar: Sidebar): SidebarItemDoc[] {
85
+ return collectSidebarItemsOfType('ref', sidebar);
86
+ }
84
87
 
85
88
  // /!\ docId order matters for navigation!
86
89
  export function collectSidebarDocIds(sidebar: Sidebar): string[] {
@@ -47,6 +47,7 @@ const sidebarItemDocSchema = sidebarItemBaseSchema.append<SidebarItemDoc>({
47
47
  type: Joi.string().valid('doc', 'ref').required(),
48
48
  id: Joi.string().required(),
49
49
  label: Joi.string(),
50
+ translatable: Joi.boolean(),
50
51
  });
51
52
 
52
53
  const sidebarItemHtmlSchema = sidebarItemBaseSchema.append<SidebarItemHtml>({
@@ -12,6 +12,8 @@ import {
12
12
  collectSidebarCategories,
13
13
  transformSidebarItems,
14
14
  collectSidebarLinks,
15
+ collectSidebarDocItems,
16
+ collectSidebarRefs,
15
17
  } from './sidebars/utils';
16
18
  import type {
17
19
  LoadedVersion,
@@ -111,7 +113,22 @@ function getSidebarTranslationFileContent(
111
113
  ]),
112
114
  );
113
115
 
114
- return mergeTranslations([categoryContent, linksContent]);
116
+ const docs = collectSidebarDocItems(sidebar)
117
+ .concat(collectSidebarRefs(sidebar))
118
+ .filter((item) => item.translatable);
119
+ const docLinksContent: TranslationFileContent = Object.fromEntries(
120
+ docs.map((doc) => [
121
+ `sidebar.${sidebarName}.doc.${doc.label!}`,
122
+ {
123
+ message: doc.label!,
124
+ description: `The label for the doc item ${doc.label!} in sidebar ${sidebarName}, linking to the doc ${
125
+ doc.id
126
+ }`,
127
+ },
128
+ ]),
129
+ );
130
+
131
+ return mergeTranslations([categoryContent, linksContent, docLinksContent]);
115
132
  }
116
133
 
117
134
  function translateSidebar({
@@ -166,6 +183,14 @@ function translateSidebar({
166
183
  ?.message ?? item.label,
167
184
  };
168
185
  }
186
+ if ((item.type === 'doc' || item.type === 'ref') && item.translatable) {
187
+ return {
188
+ ...item,
189
+ label:
190
+ sidebarsTranslations[`sidebar.${sidebarName}.doc.${item.label!}`]
191
+ ?.message ?? item.label,
192
+ };
193
+ }
169
194
  return item;
170
195
  });
171
196
  }