Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): CLI command write-translations should extract translations from @docu… #7996

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions packages/docusaurus/src/commands/writeTranslations.ts
Original file line number Diff line number Diff line change
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