@docusaurus/plugin-content-docs 2.0.0-beta.21 → 2.0.0-beta.22

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.
@@ -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
  }
package/src/types.ts CHANGED
@@ -8,7 +8,6 @@
8
8
  import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils';
9
9
  import type {
10
10
  VersionMetadata,
11
- LastUpdateData,
12
11
  LoadedVersion,
13
12
  CategoryGeneratedIndexMetadata,
14
13
  } from '@docusaurus/plugin-content-docs';
@@ -19,7 +18,6 @@ export type DocFile = {
19
18
  filePath: string; // /!\ may be localized
20
19
  source: string;
21
20
  content: string;
22
- lastUpdate: LastUpdateData;
23
21
  };
24
22
 
25
23
  export type SourceToPermalink = {
@@ -55,19 +55,16 @@ export function getVersionSidebarsPath(
55
55
  }
56
56
 
57
57
  export function getDocsDirPathLocalized({
58
- siteDir,
59
- locale,
58
+ localizationDir,
60
59
  pluginId,
61
60
  versionName,
62
61
  }: {
63
- siteDir: string;
64
- locale: string;
62
+ localizationDir: string;
65
63
  pluginId: string;
66
64
  versionName: string;
67
65
  }): string {
68
66
  return getPluginI18nPath({
69
- siteDir,
70
- locale,
67
+ localizationDir,
71
68
  pluginName: 'docusaurus-plugin-content-docs',
72
69
  pluginId,
73
70
  subPaths: [
@@ -175,8 +172,7 @@ export async function getVersionMetadataPaths({
175
172
  > {
176
173
  const isCurrent = versionName === CURRENT_VERSION_NAME;
177
174
  const contentPathLocalized = getDocsDirPathLocalized({
178
- siteDir: context.siteDir,
179
- locale: context.i18n.currentLocale,
175
+ localizationDir: context.localizationDir,
180
176
  pluginId: options.id,
181
177
  versionName,
182
178
  });
@@ -49,8 +49,7 @@ function getVersionEditUrls({
49
49
  const editDirPath = options.editCurrentVersion ? options.path : contentPath;
50
50
  const editDirPathLocalized = options.editCurrentVersion
51
51
  ? getDocsDirPathLocalized({
52
- siteDir: context.siteDir,
53
- locale: context.i18n.currentLocale,
52
+ localizationDir: context.localizationDir,
54
53
  versionName: CURRENT_VERSION_NAME,
55
54
  pluginId: options.id,
56
55
  })
package/src/deps.d.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- declare module 'remark-admonitions' {
9
- type Options = {[key: string]: unknown};
10
-
11
- const plugin: (options?: Options) => void;
12
- export = plugin;
13
- }