mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-16 00:06:11 +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
|
@ -65,34 +65,33 @@ describe('getPluginI18nPath', () => {
|
|||
it('gets correct path', () => {
|
||||
expect(
|
||||
getPluginI18nPath({
|
||||
siteDir: __dirname,
|
||||
locale: 'zh-Hans',
|
||||
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
|
||||
pluginName: 'plugin-content-docs',
|
||||
pluginId: 'community',
|
||||
subPaths: ['foo'],
|
||||
}),
|
||||
).toMatchInlineSnapshot(
|
||||
`"<PROJECT_ROOT>/packages/docusaurus-utils/src/__tests__/i18n/zh-Hans/plugin-content-docs-community/foo"`,
|
||||
`"<SITE_DIR>/i18n/zh-Hans/plugin-content-docs-community/foo"`,
|
||||
);
|
||||
});
|
||||
it('gets correct path for default plugin', () => {
|
||||
expect(
|
||||
getPluginI18nPath({
|
||||
siteDir: __dirname,
|
||||
locale: 'zh-Hans',
|
||||
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
|
||||
pluginName: 'plugin-content-docs',
|
||||
subPaths: ['foo'],
|
||||
}).replace(__dirname, ''),
|
||||
).toMatchInlineSnapshot(`"/i18n/zh-Hans/plugin-content-docs/foo"`);
|
||||
}),
|
||||
).toMatchInlineSnapshot(
|
||||
`"<SITE_DIR>/i18n/zh-Hans/plugin-content-docs/foo"`,
|
||||
);
|
||||
});
|
||||
it('gets correct path when no sub-paths', () => {
|
||||
expect(
|
||||
getPluginI18nPath({
|
||||
siteDir: __dirname,
|
||||
locale: 'zh-Hans',
|
||||
localizationDir: '<SITE_DIR>/i18n/zh-Hans',
|
||||
pluginName: 'plugin-content-docs',
|
||||
}).replace(__dirname, ''),
|
||||
).toMatchInlineSnapshot(`"/i18n/zh-Hans/plugin-content-docs"`);
|
||||
}),
|
||||
).toMatchInlineSnapshot(`"<SITE_DIR>/i18n/zh-Hans/plugin-content-docs"`);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -104,6 +103,7 @@ describe('localizePath', () => {
|
|||
path: '/baseUrl',
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'fr',
|
||||
localeConfigs: {},
|
||||
|
@ -120,6 +120,7 @@ describe('localizePath', () => {
|
|||
path: '/baseFsPath',
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'fr',
|
||||
localeConfigs: {},
|
||||
|
@ -136,6 +137,7 @@ describe('localizePath', () => {
|
|||
path: '/baseUrl/',
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
|
@ -152,6 +154,7 @@ describe('localizePath', () => {
|
|||
path: '/baseUrl/',
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
|
@ -167,6 +170,7 @@ describe('localizePath', () => {
|
|||
path: '/baseUrl/',
|
||||
i18n: {
|
||||
defaultLocale: 'en',
|
||||
path: 'i18n',
|
||||
locales: ['en', 'fr'],
|
||||
currentLocale: 'en',
|
||||
localeConfigs: {},
|
||||
|
|
|
@ -75,7 +75,7 @@ export const THEME_PATH = `${SRC_DIR_NAME}/theme`;
|
|||
* All translation-related data live here, relative to site directory. Content
|
||||
* will be namespaced by locale.
|
||||
*/
|
||||
export const I18N_DIR_NAME = 'i18n';
|
||||
export const DEFAULT_I18N_DIR_NAME = 'i18n';
|
||||
|
||||
/**
|
||||
* Translations for React code.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import path from 'path';
|
||||
import _ from 'lodash';
|
||||
import {DEFAULT_PLUGIN_ID, I18N_DIR_NAME} from './constants';
|
||||
import {DEFAULT_PLUGIN_ID} from './constants';
|
||||
import {normalizeUrl} from './urlUtils';
|
||||
import type {
|
||||
TranslationFileContent,
|
||||
|
@ -46,24 +46,18 @@ export function updateTranslationFileMessages(
|
|||
* expect everything it needs for translations to be found under this path.
|
||||
*/
|
||||
export function getPluginI18nPath({
|
||||
siteDir,
|
||||
locale,
|
||||
localizationDir,
|
||||
pluginName,
|
||||
pluginId = DEFAULT_PLUGIN_ID,
|
||||
subPaths = [],
|
||||
}: {
|
||||
siteDir: string;
|
||||
locale: string;
|
||||
localizationDir: string;
|
||||
pluginName: string;
|
||||
pluginId?: string | undefined;
|
||||
subPaths?: string[];
|
||||
}): string {
|
||||
return path.join(
|
||||
siteDir,
|
||||
I18N_DIR_NAME,
|
||||
// Namespace first by locale: convenient to work in a single folder for a
|
||||
// translator
|
||||
locale,
|
||||
localizationDir,
|
||||
// Make it convenient to use for single-instance
|
||||
// ie: return "docs", not "docs-default" nor "docs/default"
|
||||
`${pluginName}${pluginId === DEFAULT_PLUGIN_ID ? '' : `-${pluginId}`}`,
|
||||
|
|
|
@ -17,7 +17,7 @@ export {
|
|||
DEFAULT_STATIC_DIR_NAME,
|
||||
OUTPUT_STATIC_ASSETS_DIR_NAME,
|
||||
THEME_PATH,
|
||||
I18N_DIR_NAME,
|
||||
DEFAULT_I18N_DIR_NAME,
|
||||
CODE_TRANSLATIONS_FILE_NAME,
|
||||
DEFAULT_PORT,
|
||||
DEFAULT_PLUGIN_ID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue