mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
feat: allow customizing localization path of each locale (#7624)
This commit is contained in:
parent
39e3e3715e
commit
1b9bec1042
24 changed files with 254 additions and 30 deletions
|
@ -123,7 +123,7 @@ describe('localizePath', () => {
|
|||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'fr',
|
||||
localeConfigs: {},
|
||||
localeConfigs: {fr: {path: 'fr'}, en: {path: 'en'}},
|
||||
},
|
||||
options: {localizePath: true},
|
||||
}),
|
||||
|
@ -140,7 +140,7 @@ describe('localizePath', () => {
|
|||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
localeConfigs: {fr: {path: 'fr'}, en: {path: 'en'}},
|
||||
},
|
||||
options: {localizePath: true},
|
||||
}),
|
||||
|
@ -157,7 +157,7 @@ describe('localizePath', () => {
|
|||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
localeConfigs: {fr: {path: 'fr'}, en: {path: 'en'}},
|
||||
},
|
||||
}),
|
||||
).toBe('/baseUrl/');
|
||||
|
@ -173,7 +173,7 @@ describe('localizePath', () => {
|
|||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
localeConfigs: {fr: {path: 'fr'}, en: {path: 'en'}},
|
||||
},
|
||||
}),
|
||||
).toBe('/baseUrl/');
|
||||
|
|
|
@ -68,6 +68,9 @@ export function getPluginI18nPath({
|
|||
/**
|
||||
* Takes a path and returns a localized a version (which is basically `path +
|
||||
* i18n.currentLocale`).
|
||||
*
|
||||
* This is used to resolve the `outDir` and `baseUrl` of each locale; it is NOT
|
||||
* used to determine plugin localization file locations.
|
||||
*/
|
||||
export function localizePath({
|
||||
pathType,
|
||||
|
@ -94,13 +97,15 @@ export function localizePath({
|
|||
};
|
||||
}): string {
|
||||
const shouldLocalizePath: boolean =
|
||||
//
|
||||
options.localizePath ?? i18n.currentLocale !== i18n.defaultLocale;
|
||||
|
||||
if (!shouldLocalizePath) {
|
||||
return originalPath;
|
||||
}
|
||||
// FS paths need special care, for Windows support
|
||||
// FS paths need special care, for Windows support. Note: we don't use the
|
||||
// locale config's `path` here, because this function is used for resolving
|
||||
// outDir, which must be the same as baseUrl. When we have the baseUrl config,
|
||||
// we need to sync the two.
|
||||
if (pathType === 'fs') {
|
||||
return path.join(originalPath, i18n.currentLocale);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue