mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-07 11:57:55 +02:00
fix(v2): i18n should not crash theme without footer (#3940)
* Fix theme translations when no footer * fix TS issues
This commit is contained in:
parent
3fc29f4b14
commit
ef49c2be72
3 changed files with 34 additions and 7 deletions
|
@ -87,3 +87,24 @@ describe('translateThemeConfig', () => {
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getTranslationFiles and translateThemeConfig isomorphism', () => {
|
||||||
|
function verifyIsomorphism(themeConfig: ThemeConfig) {
|
||||||
|
const translationFiles = getTranslationFiles({themeConfig});
|
||||||
|
const translatedThemeConfig = translateThemeConfig({
|
||||||
|
themeConfig,
|
||||||
|
translationFiles,
|
||||||
|
});
|
||||||
|
expect(translatedThemeConfig).toEqual(themeConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('should be verified for main sample', () => {
|
||||||
|
verifyIsomorphism(ThemeConfigSample);
|
||||||
|
});
|
||||||
|
|
||||||
|
// undefined footer should not make the translation code crash
|
||||||
|
// See https://github.com/facebook/docusaurus/issues/3936
|
||||||
|
test('should be verified for sample without footer', () => {
|
||||||
|
verifyIsomorphism({...ThemeConfigSample, footer: undefined});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -129,10 +129,17 @@ export function getTranslationFiles({
|
||||||
}: {
|
}: {
|
||||||
themeConfig: ThemeConfig;
|
themeConfig: ThemeConfig;
|
||||||
}): TranslationFile[] {
|
}): TranslationFile[] {
|
||||||
return [
|
const translationFiles: (TranslationFile | undefined)[] = [
|
||||||
{path: 'navbar', content: getNavbarTranslationFile(themeConfig.navbar)},
|
{path: 'navbar', content: getNavbarTranslationFile(themeConfig.navbar)},
|
||||||
{path: 'footer', content: getFooterTranslationFile(themeConfig.footer)},
|
themeConfig.footer
|
||||||
|
? {
|
||||||
|
path: 'footer',
|
||||||
|
content: getFooterTranslationFile(themeConfig.footer),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
return translationFiles.filter(Boolean) as TranslationFile[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function translateThemeConfig({
|
export function translateThemeConfig({
|
||||||
|
@ -153,9 +160,8 @@ export function translateThemeConfig({
|
||||||
themeConfig.navbar,
|
themeConfig.navbar,
|
||||||
translationFilesMap.navbar.content,
|
translationFilesMap.navbar.content,
|
||||||
),
|
),
|
||||||
footer: translateFooter(
|
footer: themeConfig.footer
|
||||||
themeConfig.footer,
|
? translateFooter(themeConfig.footer, translationFilesMap.footer.content)
|
||||||
translationFilesMap.footer.content,
|
: undefined,
|
||||||
),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ export type ThemeConfig = {
|
||||||
colorMode: any;
|
colorMode: any;
|
||||||
announcementBar: any;
|
announcementBar: any;
|
||||||
prism: any;
|
prism: any;
|
||||||
footer: Footer;
|
footer: Footer | undefined;
|
||||||
hideableSidebar: any;
|
hideableSidebar: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue