@docusaurus/core 0.0.0-5089 → 0.0.0-5091
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/start.js +2 -10
- package/lib/commands/writeTranslations.js +5 -5
- package/lib/server/configValidation.js +2 -0
- package/lib/server/i18n.js +1 -0
- package/lib/server/index.js +6 -5
- package/lib/server/plugins/index.js +1 -2
- package/lib/server/translations/translations.d.ts +3 -5
- package/lib/server/translations/translations.js +8 -16
- package/package.json +10 -10
package/lib/commands/start.js
CHANGED
|
@@ -24,7 +24,6 @@ const server_1 = require("../server");
|
|
|
24
24
|
const client_1 = tslib_1.__importDefault(require("../webpack/client"));
|
|
25
25
|
const utils_2 = require("../webpack/utils");
|
|
26
26
|
const getHostPort_1 = require("../server/getHostPort");
|
|
27
|
-
const translations_1 = require("../server/translations/translations");
|
|
28
27
|
async function start(siteDir, cliOptions) {
|
|
29
28
|
process.env.NODE_ENV = 'development';
|
|
30
29
|
process.env.BABEL_ENV = 'development';
|
|
@@ -61,7 +60,7 @@ async function start(siteDir, cliOptions) {
|
|
|
61
60
|
logger_1.default.error(err.stack);
|
|
62
61
|
});
|
|
63
62
|
}, 500);
|
|
64
|
-
const { siteConfig, plugins } = props;
|
|
63
|
+
const { siteConfig, plugins, localizationDir } = props;
|
|
65
64
|
const normalizeToSiteDir = (filepath) => {
|
|
66
65
|
if (filepath && path_1.default.isAbsolute(filepath)) {
|
|
67
66
|
return (0, utils_1.posixPath)(path_1.default.relative(siteDir, filepath));
|
|
@@ -72,14 +71,7 @@ async function start(siteDir, cliOptions) {
|
|
|
72
71
|
.flatMap((plugin) => plugin.getPathsToWatch?.() ?? [])
|
|
73
72
|
.filter(Boolean)
|
|
74
73
|
.map(normalizeToSiteDir);
|
|
75
|
-
const pathsToWatch = [
|
|
76
|
-
...pluginPaths,
|
|
77
|
-
props.siteConfigPath,
|
|
78
|
-
(0, translations_1.getTranslationsLocaleDirPath)({
|
|
79
|
-
siteDir,
|
|
80
|
-
locale: props.i18n.currentLocale,
|
|
81
|
-
}),
|
|
82
|
-
];
|
|
74
|
+
const pathsToWatch = [...pluginPaths, props.siteConfigPath, localizationDir];
|
|
83
75
|
const pollingOptions = {
|
|
84
76
|
usePolling: !!cliOptions.poll,
|
|
85
77
|
interval: Number.isInteger(cliOptions.poll)
|
|
@@ -30,7 +30,7 @@ async function getExtraSourceCodeFilePaths() {
|
|
|
30
30
|
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
async function writePluginTranslationFiles({
|
|
33
|
+
async function writePluginTranslationFiles({ localizationDir, plugin, options, }) {
|
|
34
34
|
if (plugin.getTranslationFiles) {
|
|
35
35
|
const content = await plugin.loadContent?.();
|
|
36
36
|
const translationFiles = await plugin.getTranslationFiles({
|
|
@@ -38,10 +38,9 @@ async function writePluginTranslationFiles({ siteDir, plugin, locale, options, }
|
|
|
38
38
|
});
|
|
39
39
|
await Promise.all(translationFiles.map(async (translationFile) => {
|
|
40
40
|
await (0, translations_1.writePluginTranslations)({
|
|
41
|
-
|
|
41
|
+
localizationDir,
|
|
42
42
|
plugin,
|
|
43
43
|
translationFile,
|
|
44
|
-
locale,
|
|
45
44
|
options,
|
|
46
45
|
});
|
|
47
46
|
}));
|
|
@@ -53,6 +52,7 @@ async function writeTranslations(siteDir, options) {
|
|
|
53
52
|
config: options.config,
|
|
54
53
|
locale: options.locale,
|
|
55
54
|
});
|
|
55
|
+
const { localizationDir } = context;
|
|
56
56
|
const plugins = await (0, init_1.initPlugins)(context);
|
|
57
57
|
const locale = options.locale ?? context.i18n.defaultLocale;
|
|
58
58
|
if (!context.i18n.locales.includes(locale)) {
|
|
@@ -69,9 +69,9 @@ Available locales are: ${context.i18n.locales.join(',')}.`);
|
|
|
69
69
|
extractedCodeTranslations,
|
|
70
70
|
defaultCodeMessages,
|
|
71
71
|
});
|
|
72
|
-
await (0, translations_1.writeCodeTranslations)({
|
|
72
|
+
await (0, translations_1.writeCodeTranslations)({ localizationDir }, codeTranslations, options);
|
|
73
73
|
await Promise.all(plugins.map(async (plugin) => {
|
|
74
|
-
await writePluginTranslationFiles({
|
|
74
|
+
await writePluginTranslationFiles({ localizationDir, plugin, options });
|
|
75
75
|
}));
|
|
76
76
|
}
|
|
77
77
|
exports.writeTranslations = writeTranslations;
|
|
@@ -12,6 +12,7 @@ const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
|
12
12
|
const DEFAULT_I18N_LOCALE = 'en';
|
|
13
13
|
exports.DEFAULT_I18N_CONFIG = {
|
|
14
14
|
defaultLocale: DEFAULT_I18N_LOCALE,
|
|
15
|
+
path: utils_1.DEFAULT_I18N_DIR_NAME,
|
|
15
16
|
locales: [DEFAULT_I18N_LOCALE],
|
|
16
17
|
localeConfigs: {},
|
|
17
18
|
};
|
|
@@ -91,6 +92,7 @@ const LocaleConfigSchema = utils_validation_1.Joi.object({
|
|
|
91
92
|
});
|
|
92
93
|
const I18N_CONFIG_SCHEMA = utils_validation_1.Joi.object({
|
|
93
94
|
defaultLocale: utils_validation_1.Joi.string().required(),
|
|
95
|
+
path: utils_validation_1.Joi.string().default(exports.DEFAULT_I18N_CONFIG.path),
|
|
94
96
|
locales: utils_validation_1.Joi.array().items().min(1).items(utils_validation_1.Joi.string().required()).required(),
|
|
95
97
|
localeConfigs: utils_validation_1.Joi.object()
|
|
96
98
|
.pattern(/.*/, LocaleConfigSchema)
|
package/lib/server/i18n.js
CHANGED
package/lib/server/index.js
CHANGED
|
@@ -46,15 +46,15 @@ async function loadContext(options) {
|
|
|
46
46
|
pathType: 'fs',
|
|
47
47
|
});
|
|
48
48
|
const siteConfig = { ...initialSiteConfig, baseUrl };
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})) ?? {};
|
|
49
|
+
// TODO allow customizing localizationDir per-locale
|
|
50
|
+
const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.currentLocale);
|
|
51
|
+
const codeTranslationFileContent = (await (0, translations_1.readCodeTranslationFileContent)({ localizationDir })) ?? {};
|
|
53
52
|
// We only need key->message for code translations
|
|
54
53
|
const codeTranslations = lodash_1.default.mapValues(codeTranslationFileContent, (value) => value.message);
|
|
55
54
|
return {
|
|
56
55
|
siteDir,
|
|
57
56
|
generatedFilesDir,
|
|
57
|
+
localizationDir,
|
|
58
58
|
siteConfig,
|
|
59
59
|
siteConfigPath,
|
|
60
60
|
outDir,
|
|
@@ -73,7 +73,7 @@ exports.loadContext = loadContext;
|
|
|
73
73
|
async function load(options) {
|
|
74
74
|
const { siteDir } = options;
|
|
75
75
|
const context = await loadContext(options);
|
|
76
|
-
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, codeTranslations: siteCodeTranslations, } = context;
|
|
76
|
+
const { generatedFilesDir, siteConfig, siteConfigPath, outDir, baseUrl, i18n, localizationDir, codeTranslations: siteCodeTranslations, } = context;
|
|
77
77
|
const { plugins, pluginsRouteConfigs, globalData } = await (0, plugins_1.loadPlugins)(context);
|
|
78
78
|
const clientModules = (0, clientModules_1.loadClientModules)(plugins);
|
|
79
79
|
const { headTags, preBodyTags, postBodyTags } = (0, htmlTags_1.loadHtmlTags)(plugins);
|
|
@@ -137,6 +137,7 @@ ${Object.entries(registry)
|
|
|
137
137
|
outDir,
|
|
138
138
|
baseUrl,
|
|
139
139
|
i18n,
|
|
140
|
+
localizationDir,
|
|
140
141
|
generatedFilesDir,
|
|
141
142
|
routes: pluginsRouteConfigs,
|
|
142
143
|
routesPaths,
|
|
@@ -35,8 +35,7 @@ async function loadPlugins(context) {
|
|
|
35
35
|
const content = await plugin.loadContent?.();
|
|
36
36
|
const rawTranslationFiles = (await plugin.getTranslationFiles?.({ content })) ?? [];
|
|
37
37
|
const translationFiles = await Promise.all(rawTranslationFiles.map((translationFile) => (0, translations_1.localizePluginTranslationFile)({
|
|
38
|
-
|
|
39
|
-
siteDir: context.siteDir,
|
|
38
|
+
localizationDir: context.localizationDir,
|
|
40
39
|
translationFile,
|
|
41
40
|
plugin,
|
|
42
41
|
})));
|
|
@@ -10,18 +10,16 @@ export declare type WriteTranslationsOptions = {
|
|
|
10
10
|
messagePrefix?: string;
|
|
11
11
|
};
|
|
12
12
|
declare type TranslationContext = {
|
|
13
|
-
|
|
14
|
-
locale: string;
|
|
13
|
+
localizationDir: string;
|
|
15
14
|
};
|
|
16
|
-
export declare function getTranslationsLocaleDirPath(context: TranslationContext): string;
|
|
17
15
|
export declare function readCodeTranslationFileContent(context: TranslationContext): Promise<TranslationFileContent | undefined>;
|
|
18
16
|
export declare function writeCodeTranslations(context: TranslationContext, content: TranslationFileContent, options: WriteTranslationsOptions): Promise<void>;
|
|
19
|
-
export declare function writePluginTranslations({
|
|
17
|
+
export declare function writePluginTranslations({ localizationDir, plugin, translationFile, options, }: TranslationContext & {
|
|
20
18
|
plugin: InitializedPlugin;
|
|
21
19
|
translationFile: TranslationFile;
|
|
22
20
|
options?: WriteTranslationsOptions;
|
|
23
21
|
}): Promise<void>;
|
|
24
|
-
export declare function localizePluginTranslationFile({
|
|
22
|
+
export declare function localizePluginTranslationFile({ localizationDir, plugin, translationFile, }: TranslationContext & {
|
|
25
23
|
plugin: InitializedPlugin;
|
|
26
24
|
translationFile: TranslationFile;
|
|
27
25
|
}): Promise<TranslationFile>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent =
|
|
9
|
+
exports.applyDefaultCodeTranslations = exports.getPluginsDefaultCodeTranslationMessages = exports.localizePluginTranslationFile = exports.writePluginTranslations = exports.writeCodeTranslations = exports.readCodeTranslationFileContent = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
@@ -79,13 +79,8 @@ Maybe you should remove them? ${unknownKeys}`;
|
|
|
79
79
|
await fs_extra_1.default.outputFile(filePath, `${JSON.stringify(mergedContent, null, 2)}\n`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
// Should we make this configurable?
|
|
83
|
-
function getTranslationsLocaleDirPath(context) {
|
|
84
|
-
return path_1.default.join(context.siteDir, utils_1.I18N_DIR_NAME, context.locale);
|
|
85
|
-
}
|
|
86
|
-
exports.getTranslationsLocaleDirPath = getTranslationsLocaleDirPath;
|
|
87
82
|
function getCodeTranslationsFilePath(context) {
|
|
88
|
-
return path_1.default.join(
|
|
83
|
+
return path_1.default.join(context.localizationDir, utils_1.CODE_TRANSLATIONS_FILE_NAME);
|
|
89
84
|
}
|
|
90
85
|
async function readCodeTranslationFileContent(context) {
|
|
91
86
|
return readTranslationFileContent(getCodeTranslationsFilePath(context));
|
|
@@ -108,21 +103,19 @@ function addTranslationFileExtension(translationFilePath) {
|
|
|
108
103
|
}
|
|
109
104
|
return `${translationFilePath}.json`;
|
|
110
105
|
}
|
|
111
|
-
function getPluginTranslationFilePath({
|
|
106
|
+
function getPluginTranslationFilePath({ localizationDir, plugin, translationFilePath, }) {
|
|
112
107
|
const dirPath = (0, utils_1.getPluginI18nPath)({
|
|
113
|
-
|
|
114
|
-
locale,
|
|
108
|
+
localizationDir,
|
|
115
109
|
pluginName: plugin.name,
|
|
116
110
|
pluginId: plugin.options.id,
|
|
117
111
|
});
|
|
118
112
|
const filePath = addTranslationFileExtension(translationFilePath);
|
|
119
113
|
return path_1.default.join(dirPath, filePath);
|
|
120
114
|
}
|
|
121
|
-
async function writePluginTranslations({
|
|
115
|
+
async function writePluginTranslations({ localizationDir, plugin, translationFile, options, }) {
|
|
122
116
|
const filePath = getPluginTranslationFilePath({
|
|
123
117
|
plugin,
|
|
124
|
-
|
|
125
|
-
locale,
|
|
118
|
+
localizationDir,
|
|
126
119
|
translationFilePath: translationFile.path,
|
|
127
120
|
});
|
|
128
121
|
await writeTranslationFileContent({
|
|
@@ -132,11 +125,10 @@ async function writePluginTranslations({ siteDir, plugin, locale, translationFil
|
|
|
132
125
|
});
|
|
133
126
|
}
|
|
134
127
|
exports.writePluginTranslations = writePluginTranslations;
|
|
135
|
-
async function localizePluginTranslationFile({
|
|
128
|
+
async function localizePluginTranslationFile({ localizationDir, plugin, translationFile, }) {
|
|
136
129
|
const filePath = getPluginTranslationFilePath({
|
|
137
130
|
plugin,
|
|
138
|
-
|
|
139
|
-
locale,
|
|
131
|
+
localizationDir,
|
|
140
132
|
translationFilePath: translationFile.path,
|
|
141
133
|
});
|
|
142
134
|
const localizedContent = await readTranslationFileContent(filePath);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/core",
|
|
3
3
|
"description": "Easy to Maintain Open Source Documentation Websites",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-5091",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"@babel/runtime": "^7.18.3",
|
|
44
44
|
"@babel/runtime-corejs3": "^7.18.3",
|
|
45
45
|
"@babel/traverse": "^7.18.2",
|
|
46
|
-
"@docusaurus/cssnano-preset": "0.0.0-
|
|
47
|
-
"@docusaurus/logger": "0.0.0-
|
|
48
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
46
|
+
"@docusaurus/cssnano-preset": "0.0.0-5091",
|
|
47
|
+
"@docusaurus/logger": "0.0.0-5091",
|
|
48
|
+
"@docusaurus/mdx-loader": "0.0.0-5091",
|
|
49
49
|
"@docusaurus/react-loadable": "5.5.2",
|
|
50
|
-
"@docusaurus/utils": "0.0.0-
|
|
51
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
52
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
50
|
+
"@docusaurus/utils": "0.0.0-5091",
|
|
51
|
+
"@docusaurus/utils-common": "0.0.0-5091",
|
|
52
|
+
"@docusaurus/utils-validation": "0.0.0-5091",
|
|
53
53
|
"@slorber/static-site-generator-webpack-plugin": "^4.0.7",
|
|
54
54
|
"@svgr/webpack": "^6.2.1",
|
|
55
55
|
"autoprefixer": "^10.4.7",
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"webpackbar": "^5.0.2"
|
|
108
108
|
},
|
|
109
109
|
"devDependencies": {
|
|
110
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
111
|
-
"@docusaurus/types": "0.0.0-
|
|
110
|
+
"@docusaurus/module-type-aliases": "0.0.0-5091",
|
|
111
|
+
"@docusaurus/types": "0.0.0-5091",
|
|
112
112
|
"@types/detect-port": "^1.3.2",
|
|
113
113
|
"@types/react-dom": "^18.0.5",
|
|
114
114
|
"@types/react-router-config": "^5.0.6",
|
|
@@ -128,5 +128,5 @@
|
|
|
128
128
|
"engines": {
|
|
129
129
|
"node": ">=16.14"
|
|
130
130
|
},
|
|
131
|
-
"gitHead": "
|
|
131
|
+
"gitHead": "9f79f0eb7547d40c08306a72a3617806f2e6f2bd"
|
|
132
132
|
}
|