Skip to content

Commit 3b72bb4

Browse files
fix(docs): versioning CLI should copy localized translation file current.json to version-<v>.json (#10875)
Co-authored-by: Sungchang Ha <[email protected]>
1 parent bc3445c commit 3b72bb4

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

packages/docusaurus-plugin-content-docs/src/__tests__/__fixtures__/simple-site/i18n/zh-Hans/docusaurus-plugin-content-docs/current.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

packages/docusaurus-plugin-content-docs/src/cli.ts

+18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getVersionDocsDirPath,
1515
getVersionSidebarsPath,
1616
getDocsDirPathLocalized,
17+
getPluginDirPathLocalized,
1718
readVersionsFile,
1819
} from './versions/files';
1920
import {validateVersionName} from './versions/validation';
@@ -123,6 +124,23 @@ async function cliDocsVersionCommand(
123124
versionName: version,
124125
});
125126
await fs.copy(docsDir, newVersionDir);
127+
128+
// Copy version JSON translation file for this locale
129+
// i18n/<l>/docusaurus-plugin-content-docs/current.json => version-v1.json
130+
// See https://docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs#translation-files-location
131+
if (locale !== i18n.defaultLocale) {
132+
const dir = getPluginDirPathLocalized({
133+
localizationDir,
134+
pluginId,
135+
});
136+
const sourceFile = path.join(dir, 'current.json');
137+
const dest = path.join(dir, `version-${version}.json`);
138+
if (await fs.pathExists(sourceFile)) {
139+
await fs.copy(sourceFile, dest);
140+
} else {
141+
logger.warn`${pluginIdLogPrefix}: i18n translation file does not exist in path=${sourceFile}. Skipping.`;
142+
}
143+
}
126144
}),
127145
);
128146

packages/docusaurus-plugin-content-docs/src/versions/files.ts

+15
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ export function getDocsDirPathLocalized({
7575
});
7676
}
7777

78+
export function getPluginDirPathLocalized({
79+
localizationDir,
80+
pluginId,
81+
}: {
82+
localizationDir: string;
83+
pluginId: string;
84+
}): string {
85+
return getPluginI18nPath({
86+
localizationDir,
87+
pluginName: 'docusaurus-plugin-content-docs',
88+
pluginId,
89+
subPaths: [],
90+
});
91+
}
92+
7893
/** `community` => `[siteDir]/community_versions.json` */
7994
export function getVersionsFilePath(siteDir: string, pluginId: string): string {
8095
return path.join(siteDir, addPluginIdPrefix(VERSIONS_JSON_FILE, pluginId));

0 commit comments

Comments
 (0)