From 62c2d1b3ad27017f03472646b4d2914ea6ad5144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Wed, 24 Aug 2022 12:45:57 +0200 Subject: [PATCH] =?UTF-8?q?fix(core):=20CLI=20command=20write-translations?= =?UTF-8?q?=20should=20extract=20translations=20from=20@docu=E2=80=A6=20(#?= =?UTF-8?q?7996)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/commands/writeTranslations.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus/src/commands/writeTranslations.ts b/packages/docusaurus/src/commands/writeTranslations.ts index 6bda39cd5776..6247f04902dc 100644 --- a/packages/docusaurus/src/commands/writeTranslations.ts +++ b/packages/docusaurus/src/commands/writeTranslations.ts @@ -29,6 +29,14 @@ export type WriteTranslationsCLIOptions = Pick< > & WriteTranslationsOptions; +function resolveThemeCommonLibDir(): string | undefined { + try { + return path.dirname(require.resolve('@docusaurus/theme-common')); + } catch { + return undefined; + } +} + /** * This is a hack, so that @docusaurus/theme-common translations are extracted! * A theme doesn't have a way to express that one of its dependency (like @@ -37,14 +45,11 @@ export type WriteTranslationsCLIOptions = Pick< * We just make an exception and assume that user is using an official theme */ async function getExtraSourceCodeFilePaths(): Promise { - try { - const themeCommonSourceDir = path.dirname( - require.resolve('@docusaurus/theme-common/lib'), - ); - return globSourceCodeFilePaths([themeCommonSourceDir]); - } catch { + const themeCommonLibDir = resolveThemeCommonLibDir(); + if (!themeCommonLibDir) { return []; // User may not use a Docusaurus official theme? Quite unlikely... } + return globSourceCodeFilePaths([themeCommonLibDir]); } async function writePluginTranslationFiles({ @@ -108,6 +113,7 @@ Available locales are: ${context.i18n.locales.join(',')}.`, babelOptions, await getExtraSourceCodeFilePaths(), ); + const defaultCodeMessages = await getPluginsDefaultCodeTranslationMessages( plugins, );