mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-06 19:37:52 +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();
|
||||
});
|
||||
});
|
||||
|
||||
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;
|
||||
}): TranslationFile[] {
|
||||
return [
|
||||
const translationFiles: (TranslationFile | undefined)[] = [
|
||||
{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({
|
||||
|
@ -153,9 +160,8 @@ export function translateThemeConfig({
|
|||
themeConfig.navbar,
|
||||
translationFilesMap.navbar.content,
|
||||
),
|
||||
footer: translateFooter(
|
||||
themeConfig.footer,
|
||||
translationFilesMap.footer.content,
|
||||
),
|
||||
footer: themeConfig.footer
|
||||
? translateFooter(themeConfig.footer, translationFilesMap.footer.content)
|
||||
: undefined,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ export type ThemeConfig = {
|
|||
colorMode: any;
|
||||
announcementBar: any;
|
||||
prism: any;
|
||||
footer: Footer;
|
||||
footer: Footer | undefined;
|
||||
hideableSidebar: any;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue