mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-01 19:27:48 +02:00
fix(core): CLI command write-translations should extract translations from @docu… (#7996)
This commit is contained in:
parent
bd9f29a469
commit
cee1b4b971
1 changed files with 12 additions and 6 deletions
|
@ -29,6 +29,14 @@ export type WriteTranslationsCLIOptions = Pick<
|
||||||
> &
|
> &
|
||||||
WriteTranslationsOptions;
|
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!
|
* 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
|
* 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
|
* We just make an exception and assume that user is using an official theme
|
||||||
*/
|
*/
|
||||||
async function getExtraSourceCodeFilePaths(): Promise<string[]> {
|
async function getExtraSourceCodeFilePaths(): Promise<string[]> {
|
||||||
try {
|
const themeCommonLibDir = resolveThemeCommonLibDir();
|
||||||
const themeCommonSourceDir = path.dirname(
|
if (!themeCommonLibDir) {
|
||||||
require.resolve('@docusaurus/theme-common/lib'),
|
|
||||||
);
|
|
||||||
return globSourceCodeFilePaths([themeCommonSourceDir]);
|
|
||||||
} catch {
|
|
||||||
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
||||||
}
|
}
|
||||||
|
return globSourceCodeFilePaths([themeCommonLibDir]);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writePluginTranslationFiles({
|
async function writePluginTranslationFiles({
|
||||||
|
@ -108,6 +113,7 @@ Available locales are: ${context.i18n.locales.join(',')}.`,
|
||||||
babelOptions,
|
babelOptions,
|
||||||
await getExtraSourceCodeFilePaths(),
|
await getExtraSourceCodeFilePaths(),
|
||||||
);
|
);
|
||||||
|
|
||||||
const defaultCodeMessages = await getPluginsDefaultCodeTranslationMessages(
|
const defaultCodeMessages = await getPluginsDefaultCodeTranslationMessages(
|
||||||
plugins,
|
plugins,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue