@docusaurus/core 3.8.1-canary-6362 → 3.8.1-canary-6364

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.
@@ -58,7 +58,11 @@ async function getLocalesToBuild({ siteDir, cliOptions, }) {
58
58
  config: cliOptions.config,
59
59
  localizePath,
60
60
  });
61
- const i18n = await (0, i18n_1.loadI18n)(context.siteConfig);
61
+ const i18n = await (0, i18n_1.loadI18n)({
62
+ siteDir,
63
+ config: context.siteConfig,
64
+ currentLocale: context.siteConfig.i18n.defaultLocale // Awkward but ok
65
+ });
62
66
  const locales = cliOptions.locale ?? i18n.locales;
63
67
  return orderLocales({
64
68
  locales: locales,
@@ -5,6 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import type { I18n, DocusaurusConfig, I18nLocaleConfig } from '@docusaurus/types';
8
- import type { LoadContextParams } from './site';
9
- export declare function getDefaultLocaleConfig(locale: string): I18nLocaleConfig;
10
- export declare function loadI18n(config: DocusaurusConfig, options?: Pick<LoadContextParams, 'locale'>): Promise<I18n>;
8
+ export declare function getDefaultLocaleConfig(locale: string): Omit<I18nLocaleConfig, 'translate'>;
9
+ export declare function loadI18n({ siteDir, config, currentLocale, }: {
10
+ siteDir: string;
11
+ config: DocusaurusConfig;
12
+ currentLocale: string;
13
+ }): Promise<I18n>;
@@ -9,7 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getDefaultLocaleConfig = getDefaultLocaleConfig;
10
10
  exports.loadI18n = loadI18n;
11
11
  const tslib_1 = require("tslib");
12
+ const path_1 = tslib_1.__importDefault(require("path"));
13
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
12
14
  const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const combine_promises_1 = tslib_1.__importDefault(require("combine-promises"));
13
16
  function inferLanguageDisplayName(locale) {
14
17
  const tryLocale = (l) => {
15
18
  try {
@@ -80,9 +83,8 @@ function getDefaultLocaleConfig(locale) {
80
83
  throw new Error(`Docusaurus couldn't get default locale config for ${locale}`, { cause: e });
81
84
  }
82
85
  }
83
- async function loadI18n(config, options) {
86
+ async function loadI18n({ siteDir, config, currentLocale, }) {
84
87
  const { i18n: i18nConfig } = config;
85
- const currentLocale = options?.locale ?? i18nConfig.defaultLocale;
86
88
  if (!i18nConfig.locales.includes(currentLocale)) {
87
89
  logger_1.default.warn `The locale name=${currentLocale} was not found in your site configuration: Available locales are: ${i18nConfig.locales}
88
90
  Note: Docusaurus only support running one locale at a time.`;
@@ -90,13 +92,24 @@ Note: Docusaurus only support running one locale at a time.`;
90
92
  const locales = i18nConfig.locales.includes(currentLocale)
91
93
  ? i18nConfig.locales
92
94
  : i18nConfig.locales.concat(currentLocale);
93
- function getLocaleConfig(locale) {
94
- return {
95
+ async function getFullLocaleConfig(locale) {
96
+ const localeConfigInput = i18nConfig.localeConfigs[locale] ?? {};
97
+ const localeConfig = {
95
98
  ...getDefaultLocaleConfig(locale),
96
- ...i18nConfig.localeConfigs[locale],
99
+ ...localeConfigInput,
100
+ };
101
+ // By default, translations will be enabled if i18n/<locale> dir exists
102
+ async function inferTranslate() {
103
+ const localizationDir = path_1.default.resolve(siteDir, i18nConfig.path, localeConfig.path);
104
+ return fs_extra_1.default.pathExists(localizationDir);
105
+ }
106
+ const translate = localeConfigInput.translate ?? (await inferTranslate());
107
+ return {
108
+ ...localeConfig,
109
+ translate,
97
110
  };
98
111
  }
99
- const localeConfigs = Object.fromEntries(locales.map((locale) => [locale, getLocaleConfig(locale)]));
112
+ const localeConfigs = await (0, combine_promises_1.default)(Object.fromEntries(locales.map((locale) => [locale, getFullLocaleConfig(locale)])));
100
113
  return {
101
114
  defaultLocale: i18nConfig.defaultLocale,
102
115
  locales,
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.loadPlugins = loadPlugins;
10
10
  exports.reloadPlugin = reloadPlugin;
11
11
  const logger_1 = require("@docusaurus/logger");
12
+ const utils_1 = require("@docusaurus/utils");
12
13
  const init_1 = require("./init");
13
14
  const synthetic_1 = require("./synthetic");
14
15
  const translations_1 = require("../translations/translations");
@@ -37,11 +38,16 @@ async function translatePluginContent({ plugin, content, context, }) {
37
38
  async function executePluginContentLoading({ plugin, context, }) {
38
39
  return logger_1.PerfLogger.async(`Load ${(0, pluginsUtils_1.formatPluginName)(plugin)}`, async () => {
39
40
  let content = await logger_1.PerfLogger.async('loadContent()', () => plugin.loadContent?.());
40
- content = await logger_1.PerfLogger.async('translatePluginContent()', () => translatePluginContent({
41
- plugin,
42
- content,
43
- context,
44
- }));
41
+ const shouldTranslate = (0, utils_1.getLocaleConfig)(context.i18n).translate;
42
+ if (shouldTranslate) {
43
+ content = await logger_1.PerfLogger.async('translatePluginContent()', () => translatePluginContent({
44
+ plugin,
45
+ content,
46
+ context,
47
+ }));
48
+ }
49
+ // If shouldTranslate === false, we still need the code translations
50
+ // Otherwise an unlocalized French site would show code strings in English
45
51
  const defaultCodeTranslations = (await logger_1.PerfLogger.async('getDefaultCodeTranslationMessages()', () => plugin.getDefaultCodeTranslationMessages?.())) ?? {};
46
52
  if (!plugin.contentLoaded) {
47
53
  return {
@@ -46,7 +46,11 @@ async function loadContext(params) {
46
46
  const currentBundler = await (0, bundler_1.getCurrentBundler)({
47
47
  siteConfig: initialSiteConfig,
48
48
  });
49
- const i18n = await (0, i18n_1.loadI18n)(initialSiteConfig, { locale });
49
+ const i18n = await (0, i18n_1.loadI18n)({
50
+ siteDir,
51
+ config: initialSiteConfig,
52
+ currentLocale: locale ?? initialSiteConfig.i18n.defaultLocale,
53
+ });
50
54
  const baseUrl = (0, utils_1.localizePath)({
51
55
  path: initialSiteConfig.baseUrl,
52
56
  i18n,
@@ -59,7 +63,7 @@ async function loadContext(params) {
59
63
  options: params,
60
64
  pathType: 'fs',
61
65
  });
62
- const localizationDir = path_1.default.resolve(siteDir, i18n.path, i18n.localeConfigs[i18n.currentLocale].path);
66
+ const localizationDir = path_1.default.resolve(siteDir, i18n.path, (0, utils_1.getLocaleConfig)(i18n).path);
63
67
  const siteConfig = { ...initialSiteConfig, baseUrl };
64
68
  const codeTranslations = await (0, translations_1.loadSiteCodeTranslations)({ localizationDir });
65
69
  const siteStorage = (0, storage_1.createSiteStorage)(siteConfig);
@@ -15,6 +15,7 @@ const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
15
15
  const react_loadable_ssr_addon_v5_slorber_1 = tslib_1.__importDefault(require("react-loadable-ssr-addon-v5-slorber"));
16
16
  const html_webpack_plugin_1 = tslib_1.__importDefault(require("html-webpack-plugin"));
17
17
  const bundler_1 = require("@docusaurus/bundler");
18
+ const utils_1 = require("@docusaurus/utils");
18
19
  const base_1 = require("./base");
19
20
  const ChunkAssetPlugin_1 = tslib_1.__importDefault(require("./plugins/ChunkAssetPlugin"));
20
21
  const ForceTerminatePlugin_1 = tslib_1.__importDefault(require("./plugins/ForceTerminatePlugin"));
@@ -84,7 +85,7 @@ async function createStartClientConfig({ props, minify, poll, faster, configureW
84
85
  headTags,
85
86
  preBodyTags,
86
87
  postBodyTags,
87
- lang: props.i18n.localeConfigs[props.i18n.currentLocale].htmlLang,
88
+ lang: (0, utils_1.getLocaleConfig)(props.i18n).htmlLang,
88
89
  }),
89
90
  ],
90
91
  });
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": "3.8.1-canary-6362",
4
+ "version": "3.8.1-canary-6364",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -33,13 +33,13 @@
33
33
  "url": "https://github.com/facebook/docusaurus/issues"
34
34
  },
35
35
  "dependencies": {
36
- "@docusaurus/babel": "3.8.1-canary-6362",
37
- "@docusaurus/bundler": "3.8.1-canary-6362",
38
- "@docusaurus/logger": "3.8.1-canary-6362",
39
- "@docusaurus/mdx-loader": "3.8.1-canary-6362",
40
- "@docusaurus/utils": "3.8.1-canary-6362",
41
- "@docusaurus/utils-common": "3.8.1-canary-6362",
42
- "@docusaurus/utils-validation": "3.8.1-canary-6362",
36
+ "@docusaurus/babel": "3.8.1-canary-6364",
37
+ "@docusaurus/bundler": "3.8.1-canary-6364",
38
+ "@docusaurus/logger": "3.8.1-canary-6364",
39
+ "@docusaurus/mdx-loader": "3.8.1-canary-6364",
40
+ "@docusaurus/utils": "3.8.1-canary-6364",
41
+ "@docusaurus/utils-common": "3.8.1-canary-6364",
42
+ "@docusaurus/utils-validation": "3.8.1-canary-6364",
43
43
  "boxen": "^6.2.1",
44
44
  "chalk": "^4.1.2",
45
45
  "chokidar": "^3.5.3",
@@ -77,8 +77,8 @@
77
77
  "webpack-merge": "^6.0.1"
78
78
  },
79
79
  "devDependencies": {
80
- "@docusaurus/module-type-aliases": "3.8.1-canary-6362",
81
- "@docusaurus/types": "3.8.1-canary-6362",
80
+ "@docusaurus/module-type-aliases": "3.8.1-canary-6364",
81
+ "@docusaurus/types": "3.8.1-canary-6364",
82
82
  "@total-typescript/shoehorn": "^0.1.2",
83
83
  "@types/detect-port": "^1.3.3",
84
84
  "@types/react-dom": "^18.2.7",
@@ -98,5 +98,5 @@
98
98
  "engines": {
99
99
  "node": ">=18.0"
100
100
  },
101
- "gitHead": "fb5e2407590e2ec2155298195df6ca0db1026801"
101
+ "gitHead": "eb21e3eaf84009a29feff55780bb5d3a76658d01"
102
102
  }