fix(docs): versioning CLI should copy localized translation file current.json to version-<v>.json (#10875)

Co-authored-by: Sungchang Ha <bryan98@naver.com>
This commit is contained in:
jkboxomine 2025-01-31 20:50:13 +09:00 committed by GitHub
parent bc3445c344
commit 3b72bb43db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import {
getVersionDocsDirPath,
getVersionSidebarsPath,
getDocsDirPathLocalized,
getPluginDirPathLocalized,
readVersionsFile,
} from './versions/files';
import {validateVersionName} from './versions/validation';
@ -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.`;
}
}
}),
);

View file

@ -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));