feat(core): allow customizing the i18n directory path (#7386)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2022-06-02 23:37:14 +08:00 committed by GitHub
parent c07a514730
commit abe5450526
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 147 additions and 166 deletions

View file

@ -55,19 +55,19 @@ exports[`docusaurus-plugin-content-pages loads simple pages 1`] = `
exports[`docusaurus-plugin-content-pages loads simple pages with french translations 1`] = `
[
{
"permalink": "/",
"permalink": "/fr/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
{
"permalink": "/typescript",
"permalink": "/fr/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
{
"description": "Markdown index page",
"frontMatter": {},
"permalink": "/hello/",
"permalink": "/fr/hello/",
"source": "@site/src/pages/hello/index.md",
"title": "Index",
"type": "mdx",
@ -78,26 +78,26 @@ exports[`docusaurus-plugin-content-pages loads simple pages with french translat
"description": "my mdx page",
"title": "mdx page",
},
"permalink": "/hello/mdxPage",
"permalink": "/fr/hello/mdxPage",
"source": "@site/src/pages/hello/mdxPage.mdx",
"title": "mdx page",
"type": "mdx",
},
{
"permalink": "/hello/translatedJs",
"permalink": "/fr/hello/translatedJs",
"source": "@site/i18n/fr/docusaurus-plugin-content-pages/hello/translatedJs.js",
"type": "jsx",
},
{
"description": "translated markdown page (fr)",
"frontMatter": {},
"permalink": "/hello/translatedMd",
"permalink": "/fr/hello/translatedMd",
"source": "@site/i18n/fr/docusaurus-plugin-content-pages/hello/translatedMd.md",
"title": undefined,
"type": "mdx",
},
{
"permalink": "/hello/world",
"permalink": "/fr/hello/world",
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},

View file

@ -32,15 +32,9 @@ describe('docusaurus-plugin-content-pages', () => {
it('loads simple pages with french translations', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext({siteDir});
const context = await loadContext({siteDir, locale: 'fr'});
const plugin = pluginContentPages(
{
...context,
i18n: {
...context.i18n,
currentLocale: 'fr',
},
},
context,
validateOptions({
validate: normalizePluginOptions,
options: {

View file

@ -48,18 +48,12 @@ export default function pluginContentPages(
[admonitions, options.admonitions],
]);
}
const {
siteConfig,
siteDir,
generatedFilesDir,
i18n: {currentLocale},
} = context;
const {siteConfig, siteDir, generatedFilesDir, localizationDir} = context;
const contentPaths: PagesContentPaths = {
contentPath: path.resolve(siteDir, options.path),
contentPathLocalized: getPluginI18nPath({
siteDir,
locale: currentLocale,
localizationDir,
pluginName: 'docusaurus-plugin-content-pages',
pluginId: options.id,
}),