mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
feat(core): allow customizing the i18n directory path (#7386)
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
c07a514730
commit
abe5450526
26 changed files with 147 additions and 166 deletions
Binary file not shown.
|
@ -85,13 +85,15 @@ export async function cliDocsVersionCommand(
|
|||
|
||||
await Promise.all(
|
||||
i18n.locales.map(async (locale) => {
|
||||
// TODO duplicated logic from core, so duplicate comment as well: we need
|
||||
// to support customization per-locale in the future
|
||||
const localizationDir = path.resolve(siteDir, i18n.path, locale);
|
||||
// Copy docs files.
|
||||
const docsDir =
|
||||
locale === i18n.defaultLocale
|
||||
? path.resolve(siteDir, docsPath)
|
||||
: getDocsDirPathLocalized({
|
||||
siteDir,
|
||||
locale,
|
||||
localizationDir,
|
||||
pluginId,
|
||||
versionName: CURRENT_VERSION_NAME,
|
||||
});
|
||||
|
@ -114,8 +116,7 @@ export async function cliDocsVersionCommand(
|
|||
locale === i18n.defaultLocale
|
||||
? getVersionDocsDirPath(siteDir, pluginId, version)
|
||||
: getDocsDirPathLocalized({
|
||||
siteDir,
|
||||
locale,
|
||||
localizationDir,
|
||||
pluginId,
|
||||
versionName: version,
|
||||
});
|
||||
|
|
|
@ -17,6 +17,7 @@ import type {
|
|||
} from '@docusaurus/plugin-content-docs';
|
||||
|
||||
const DefaultI18N: I18n = {
|
||||
path: 'i18n',
|
||||
currentLocale: 'en',
|
||||
locales: ['en'],
|
||||
defaultLocale: 'en',
|
||||
|
@ -37,6 +38,7 @@ describe('readVersionsMetadata', () => {
|
|||
siteDir: simpleSiteDir,
|
||||
baseUrl: '/',
|
||||
i18n: DefaultI18N,
|
||||
localizationDir: path.join(simpleSiteDir, 'i18n/en'),
|
||||
} as LoadContext;
|
||||
|
||||
const vCurrent: VersionMetadata = {
|
||||
|
@ -198,6 +200,7 @@ describe('readVersionsMetadata', () => {
|
|||
siteDir: versionedSiteDir,
|
||||
baseUrl: '/',
|
||||
i18n: DefaultI18N,
|
||||
localizationDir: path.join(versionedSiteDir, 'i18n/en'),
|
||||
} as LoadContext;
|
||||
|
||||
const vCurrent: VersionMetadata = {
|
||||
|
@ -636,6 +639,7 @@ describe('readVersionsMetadata', () => {
|
|||
siteDir: versionedSiteDir,
|
||||
baseUrl: '/',
|
||||
i18n: DefaultI18N,
|
||||
localizationDir: path.join(versionedSiteDir, 'i18n/en'),
|
||||
} as LoadContext;
|
||||
|
||||
const vCurrent: VersionMetadata = {
|
||||
|
|
|
@ -55,19 +55,16 @@ export function getVersionSidebarsPath(
|
|||
}
|
||||
|
||||
export function getDocsDirPathLocalized({
|
||||
siteDir,
|
||||
locale,
|
||||
localizationDir,
|
||||
pluginId,
|
||||
versionName,
|
||||
}: {
|
||||
siteDir: string;
|
||||
locale: string;
|
||||
localizationDir: string;
|
||||
pluginId: string;
|
||||
versionName: string;
|
||||
}): string {
|
||||
return getPluginI18nPath({
|
||||
siteDir,
|
||||
locale,
|
||||
localizationDir,
|
||||
pluginName: 'docusaurus-plugin-content-docs',
|
||||
pluginId,
|
||||
subPaths: [
|
||||
|
@ -175,8 +172,7 @@ export async function getVersionMetadataPaths({
|
|||
> {
|
||||
const isCurrent = versionName === CURRENT_VERSION_NAME;
|
||||
const contentPathLocalized = getDocsDirPathLocalized({
|
||||
siteDir: context.siteDir,
|
||||
locale: context.i18n.currentLocale,
|
||||
localizationDir: context.localizationDir,
|
||||
pluginId: options.id,
|
||||
versionName,
|
||||
});
|
||||
|
|
|
@ -49,8 +49,7 @@ function getVersionEditUrls({
|
|||
const editDirPath = options.editCurrentVersion ? options.path : contentPath;
|
||||
const editDirPathLocalized = options.editCurrentVersion
|
||||
? getDocsDirPathLocalized({
|
||||
siteDir: context.siteDir,
|
||||
locale: context.i18n.currentLocale,
|
||||
localizationDir: context.localizationDir,
|
||||
versionName: CURRENT_VERSION_NAME,
|
||||
pluginId: options.id,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue