mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 23:08:54 +02:00
feat(v2): core v2 i18n support + Docusaurus site Crowdin integration (#3325)
* docs i18n initial poc * docs i18n initial poc * docs i18n initial poc * docs i18n initial poc * crowdin-v2 attempt * fix source * use crowdin env variable * try to install crowdin on netlify * try to install crowdin on netlify * try to use crowdin jar directly * try to curl the crowdin jar * add java version cmd * try to run crowdin jar in netlify * fix translatedDocsDirPath * fix loadContext issue due to site baseUrl not being modified in generted config file * real validateLocalesFile * add locale option to deploy command * better LocalizationFile type * create util getPluginI18nPath * better core localization context loading code * More explicit VersionMetadata type for localized docs folders * Ability to translate blog posts with Crowdin! * blog: refactor markdown loader + report broken links + try to get linkify working better * upgrade crowdin config to upload all docs folder files except source code related files * try to support translated pages * make markdown pages translation work * add write-translations cli command template * fix site not reloaded with correct options * refactor a bit the read/write of @generated/i18n.json file * Add <Translate> + translate() API + use it on the docusaurus homepage * watch locale translation dir * early POC of adding babel parsing for translation extraction * fs.stat => pathExists * add install:fast script * TSC: noUnusedLocals false as it's already checked by eslint * POC of extracting translations from source code * minor typo * fix extracted key to code * initial docs extracted translations * stable plugin translations POC * add crowdin commands * quickfix for i18n deployment * POC of themeConfig translation * add ability to have localized site without path prefix * sidebar typo * refactor translation system to output multiple translation files * translate properly the docs plugin * improve theme classic translation * rework translation extractor to handle new Chrome I18n JSON format (include id/description) * writeTranslations: allow to pass locales cli arg * fix ThemeConfig TS issues * fix localizePath errors * temporary add write-translations to netlify deploy preview * complete example of french translated folder * update fr folder * remove all translations from repo * minor translation refactors * fix all docs-related tests * fix blog feed tests * fix last blog tests * refactor i18n context a bit, extract codeTranslations in an extra generated file * improve @generated/i18n type * fix some i18n todos * minor refactor * fix logo typing issue after merge * move i18n.json to siteConfig instead * try to fix windows CI build * fix config test * attempt to fix windows non-posix path * increase v1 minify css jest timeout due to flaky test * proper support for localizePath on windows * remove non-functional install:fast * docs, fix docsDirPathLocalized * fix Docs i18n / md linkify issues * ensure theme-classic swizzling will use "nextjs" sources (transpiled less aggressively, to make them human readable) * fix some snapshots * improve themeConfig translation code * refactor a bit getPluginI18nPath * readTranslationFileContent => ensure files are valid, fail fast * fix versions tests * add extractSourceCodeAstTranslations comments/resource links * ignore eslint: packages/docusaurus-theme-classic/lib-next/ * fix windows CI with cross-env * crowdin ignore .DS_Store * improve writeTranslations + add exhaustive tests for translations.ts * remove typo * Wire currentLocale to algolia search * improve i18n locale error * Add tests for translationsExtractor.ts * better code translation extraction regarding statically evaluable code * fix typo * fix typo * improve theme-classic transpilation * refactor + add i18n tests * typo * test new utils * add missing snapshots * fix snapshot * blog onBrokenMarkdownLink * add sidebars tests * theme-classic index should now use ES modules * tests for theme-classic translations * useless comment * add more translation tests * simplify/cleanup writeTranslations * try to fix Netlify fr deployment * blog: test translated md is used during feed generation * blog: better i18n tests regarding editUrl + md translation application * more i18n tests for docs plugin * more i18n tests for docs plugin * Add tests for pages i18n * polish docusaurus build i18n logs
This commit is contained in:
parent
85fe96d112
commit
3166fab307
107 changed files with 5447 additions and 649 deletions
|
@ -106,7 +106,7 @@ Entries created:
|
|||
|
||||
test('site with wrong sidebar file', async () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const context = loadContext(siteDir);
|
||||
const context = await loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'wrong-sidebars.json');
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
|
@ -119,9 +119,9 @@ test('site with wrong sidebar file', async () => {
|
|||
|
||||
describe('empty/no docs website', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'empty-site');
|
||||
const context = loadContext(siteDir);
|
||||
|
||||
test('no files in docs folder', async () => {
|
||||
const context = await loadContext(siteDir);
|
||||
await fs.ensureDir(path.join(siteDir, 'docs'));
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
|
@ -135,6 +135,7 @@ describe('empty/no docs website', () => {
|
|||
});
|
||||
|
||||
test('docs folder does not exist', async () => {
|
||||
const context = await loadContext(siteDir);
|
||||
expect(() =>
|
||||
pluginContentDocs(
|
||||
context,
|
||||
|
@ -149,20 +150,25 @@ describe('empty/no docs website', () => {
|
|||
});
|
||||
|
||||
describe('simple website', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const context = loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
path: 'docs',
|
||||
sidebarPath,
|
||||
homePageId: 'hello',
|
||||
}),
|
||||
);
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
async function loadSite() {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'simple-site');
|
||||
const context = await loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
path: 'docs',
|
||||
sidebarPath,
|
||||
homePageId: 'hello',
|
||||
}),
|
||||
);
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
|
||||
test('extendCli - docsVersion', () => {
|
||||
return {siteDir, context, sidebarPath, plugin, pluginContentDir};
|
||||
}
|
||||
|
||||
test('extendCli - docsVersion', async () => {
|
||||
const {siteDir, sidebarPath, plugin} = await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
|
@ -178,7 +184,9 @@ describe('simple website', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', () => {
|
||||
test('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
|
@ -187,6 +195,7 @@ describe('simple website', () => {
|
|||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
]
|
||||
`);
|
||||
|
@ -203,6 +212,8 @@ describe('simple website', () => {
|
|||
});
|
||||
|
||||
test('configureWebpack', async () => {
|
||||
const {plugin} = await loadSite();
|
||||
|
||||
const config = applyConfigureWebpack(
|
||||
plugin.configureWebpack,
|
||||
{
|
||||
|
@ -219,6 +230,7 @@ describe('simple website', () => {
|
|||
});
|
||||
|
||||
test('content', async () => {
|
||||
const {siteDir, plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(1);
|
||||
const [currentVersion] = content.loadedVersions;
|
||||
|
@ -287,22 +299,32 @@ describe('simple website', () => {
|
|||
});
|
||||
|
||||
describe('versioned website', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const context = loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const routeBasePath = 'docs';
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
async function loadSite() {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const context = await loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'sidebars.json');
|
||||
const routeBasePath = 'docs';
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
homePageId: 'hello',
|
||||
}),
|
||||
);
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
return {
|
||||
siteDir,
|
||||
context,
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
homePageId: 'hello',
|
||||
}),
|
||||
);
|
||||
plugin,
|
||||
pluginContentDir,
|
||||
};
|
||||
}
|
||||
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
|
||||
test('extendCli - docsVersion', () => {
|
||||
test('extendCli - docsVersion', async () => {
|
||||
const {siteDir, routeBasePath, sidebarPath, plugin} = await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
|
@ -318,7 +340,8 @@ describe('versioned website', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', () => {
|
||||
test('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
|
@ -327,12 +350,16 @@ describe('versioned website', () => {
|
|||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/current/**/*.{md,mdx}",
|
||||
"docs/**/*.{md,mdx}",
|
||||
"versioned_sidebars/version-1.0.1-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.1/**/*.{md,mdx}",
|
||||
"versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
"versioned_sidebars/version-withSlugs-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs/version-withSlugs/**/*.{md,mdx}",
|
||||
"versioned_docs/version-withSlugs/**/*.{md,mdx}",
|
||||
]
|
||||
`);
|
||||
|
@ -369,6 +396,7 @@ describe('versioned website', () => {
|
|||
});
|
||||
|
||||
test('content', async () => {
|
||||
const {siteDir, plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(4);
|
||||
const [
|
||||
|
@ -499,23 +527,41 @@ describe('versioned website', () => {
|
|||
});
|
||||
|
||||
describe('versioned website (community)', () => {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const context = loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'community_sidebars.json');
|
||||
const routeBasePath = 'community';
|
||||
const pluginId = 'community';
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
id: 'community',
|
||||
path: 'community',
|
||||
async function loadSite() {
|
||||
const siteDir = path.join(__dirname, '__fixtures__', 'versioned-site');
|
||||
const context = await loadContext(siteDir);
|
||||
const sidebarPath = path.join(siteDir, 'community_sidebars.json');
|
||||
const routeBasePath = 'community';
|
||||
const pluginId = 'community';
|
||||
const plugin = pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
id: 'community',
|
||||
path: 'community',
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
}),
|
||||
);
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
return {
|
||||
siteDir,
|
||||
context,
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
}),
|
||||
);
|
||||
const pluginContentDir = path.join(context.generatedFilesDir, plugin.name);
|
||||
pluginId,
|
||||
plugin,
|
||||
pluginContentDir,
|
||||
};
|
||||
}
|
||||
|
||||
test('extendCli - docsVersion', () => {
|
||||
test('extendCli - docsVersion', async () => {
|
||||
const {
|
||||
siteDir,
|
||||
routeBasePath,
|
||||
sidebarPath,
|
||||
pluginId,
|
||||
plugin,
|
||||
} = await loadSite();
|
||||
const mock = jest
|
||||
.spyOn(cliDocs, 'cliDocsVersionCommand')
|
||||
.mockImplementation();
|
||||
|
@ -531,7 +577,8 @@ describe('versioned website (community)', () => {
|
|||
mock.mockRestore();
|
||||
});
|
||||
|
||||
test('getPathToWatch', () => {
|
||||
test('getPathToWatch', async () => {
|
||||
const {siteDir, plugin} = await loadSite();
|
||||
const pathToWatch = plugin.getPathsToWatch!();
|
||||
const matchPattern = pathToWatch.map((filepath) =>
|
||||
posixPath(path.relative(siteDir, filepath)),
|
||||
|
@ -540,8 +587,10 @@ describe('versioned website (community)', () => {
|
|||
expect(matchPattern).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
"community_sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/current/**/*.{md,mdx}",
|
||||
"community/**/*.{md,mdx}",
|
||||
"community_versioned_sidebars/version-1.0.0-sidebars.json",
|
||||
"i18n/en/docusaurus-plugin-content-docs-community/version-1.0.0/**/*.{md,mdx}",
|
||||
"community_versioned_docs/version-1.0.0/**/*.{md,mdx}",
|
||||
]
|
||||
`);
|
||||
|
@ -568,6 +617,7 @@ describe('versioned website (community)', () => {
|
|||
});
|
||||
|
||||
test('content', async () => {
|
||||
const {siteDir, plugin, pluginContentDir} = await loadSite();
|
||||
const content = await plugin.loadContent!();
|
||||
expect(content.loadedVersions.length).toEqual(2);
|
||||
const [currentVersion, version100] = content.loadedVersions;
|
||||
|
@ -579,13 +629,17 @@ describe('versioned website (community)', () => {
|
|||
isDocsHomePage: false,
|
||||
permalink: '/community/next/team',
|
||||
slug: '/team',
|
||||
/*
|
||||
source: path.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
'team.md',
|
||||
),
|
||||
title: 'team',
|
||||
description: 'Team current version',
|
||||
*/
|
||||
source:
|
||||
'@site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md',
|
||||
title: 'Team title translated',
|
||||
description: 'Team current version (translated)',
|
||||
version: 'current',
|
||||
sidebar: 'community',
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue