mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-31 23:40:39 +02:00
fix: fix write-translations warning for theme-common translations (#5398)
This commit is contained in:
parent
631c4685fb
commit
0480afc75f
2 changed files with 28 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
import {ConfigOptions, InitializedPlugin} from '@docusaurus/types';
|
||||
import path from 'path';
|
||||
import {loadContext, loadPluginConfigs} from '../server';
|
||||
import initPlugins from '../server/plugins/init';
|
||||
|
||||
|
@ -15,9 +16,27 @@ import {
|
|||
getPluginsDefaultCodeTranslationMessages,
|
||||
applyDefaultCodeTranslations,
|
||||
} from '../server/translations/translations';
|
||||
import {extractSiteSourceCodeTranslations} from '../server/translations/translationsExtractor';
|
||||
import {
|
||||
extractSiteSourceCodeTranslations,
|
||||
globSourceCodeFilePaths,
|
||||
} from '../server/translations/translationsExtractor';
|
||||
import {getCustomBabelConfigFilePath, getBabelOptions} from '../webpack/utils';
|
||||
|
||||
// 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 @docusaurus/theme-common) also has translations to extract
|
||||
// Instead of introducing a new lifecycle (like plugin.getThemeTranslationPaths() ?)
|
||||
// We just make an exception and assume that Docusaurus 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 (e) {
|
||||
return []; // User may not use a Docusaurus official theme? Quite unlikely...
|
||||
}
|
||||
}
|
||||
|
||||
async function writePluginTranslationFiles({
|
||||
siteDir,
|
||||
plugin,
|
||||
|
@ -80,6 +99,7 @@ Available locales are: ${context.i18n.locales.join(',')}.`,
|
|||
siteDir,
|
||||
plugins,
|
||||
babelOptions,
|
||||
await getExtraSourceCodeFilePaths(),
|
||||
);
|
||||
const defaultCodeMessages = await getPluginsDefaultCodeTranslationMessages(
|
||||
plugins,
|
||||
|
|
|
@ -80,6 +80,7 @@ export async function extractSiteSourceCodeTranslations(
|
|||
siteDir: string,
|
||||
plugins: InitializedPlugin[],
|
||||
babelOptions: TransformOptions,
|
||||
extraSourceCodeFilePaths: string[] = [],
|
||||
): Promise<TranslationFileContent> {
|
||||
// Should we warn here if the same translation "key" is found in multiple source code files?
|
||||
function toTranslationFileContent(
|
||||
|
@ -92,8 +93,13 @@ export async function extractSiteSourceCodeTranslations(
|
|||
|
||||
const sourceCodeFilePaths = await getSourceCodeFilePaths(siteDir, plugins);
|
||||
|
||||
const allSourceCodeFilePaths = [
|
||||
...sourceCodeFilePaths,
|
||||
...extraSourceCodeFilePaths,
|
||||
];
|
||||
|
||||
const sourceCodeFilesTranslations = await extractAllSourceCodeFileTranslations(
|
||||
sourceCodeFilePaths,
|
||||
allSourceCodeFilePaths,
|
||||
babelOptions,
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue