Skip to content

Commit

Permalink
fix(core): CLI command write-translations should extract translations…
Browse files Browse the repository at this point in the history
… from @Docu… (#7996)
  • Loading branch information
slorber committed Sep 1, 2022
1 parent 0a2ab30 commit 62c2d1b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/docusaurus/src/commands/writeTranslations.ts
Expand Up @@ -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
Expand All @@ -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<string[]> {
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({
Expand Down Expand Up @@ -108,6 +113,7 @@ Available locales are: ${context.i18n.locales.join(',')}.`,
babelOptions,
await getExtraSourceCodeFilePaths(),
);

const defaultCodeMessages = await getPluginsDefaultCodeTranslationMessages(
plugins,
);
Expand Down

0 comments on commit 62c2d1b

Please sign in to comment.