Skip to content

Commit

Permalink
fix(docs): versioning CLI should copy localized translation file `cur…
Browse files Browse the repository at this point in the history
…rent.json` to `version-<v>.json` (#10875)

Co-authored-by: Sungchang Ha <[email protected]>
  • Loading branch information
jkboxomine and sungchang-ha authored Jan 31, 2025
1 parent bc3445c commit 3b72bb4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified packages/docusaurus-plugin-content-docs/src/__tests__/cli.test.ts
Binary file not shown.
18 changes: 18 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getVersionDocsDirPath,
getVersionSidebarsPath,
getDocsDirPathLocalized,
getPluginDirPathLocalized,
readVersionsFile,
} from './versions/files';
import {validateVersionName} from './versions/validation';
Expand Down Expand Up @@ -123,6 +124,23 @@ async function cliDocsVersionCommand(
versionName: version,
});
await fs.copy(docsDir, newVersionDir);

// Copy version JSON translation file for this locale
// i18n/<l>/docusaurus-plugin-content-docs/current.json => version-v1.json
// See https://docusaurus.io/docs/next/api/plugins/@docusaurus/plugin-content-docs#translation-files-location
if (locale !== i18n.defaultLocale) {
const dir = getPluginDirPathLocalized({
localizationDir,
pluginId,
});
const sourceFile = path.join(dir, 'current.json');
const dest = path.join(dir, `version-${version}.json`);
if (await fs.pathExists(sourceFile)) {
await fs.copy(sourceFile, dest);
} else {
logger.warn`${pluginIdLogPrefix}: i18n translation file does not exist in path=${sourceFile}. Skipping.`;
}
}
}),
);

Expand Down
15 changes: 15 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/versions/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ export function getDocsDirPathLocalized({
});
}

export function getPluginDirPathLocalized({
localizationDir,
pluginId,
}: {
localizationDir: string;
pluginId: string;
}): string {
return getPluginI18nPath({
localizationDir,
pluginName: 'docusaurus-plugin-content-docs',
pluginId,
subPaths: [],
});
}

/** `community` => `[siteDir]/community_versions.json` */
export function getVersionsFilePath(siteDir: string, pluginId: string): string {
return path.join(siteDir, addPluginIdPrefix(VERSIONS_JSON_FILE, pluginId));
Expand Down

0 comments on commit 3b72bb4

Please sign in to comment.