♻️ refactor: Simplify index page component and remove internationalization configuration

- Remove debugging and fallback language settings from `next-i18next.config.js`
- Conditionally set `localePath` based on the environment
- Simplify `index.page.tsx` by removing unused imports and consolidating code
- Update `getStaticProps` to pass translation props to the page component

These changes were made to improve code readability and remove unnecessary configuration settings related to internationalization.
This commit is contained in:
canisminor1990
2023-07-16 11:32:15 +08:00
parent 85e5007e14
commit 47c3f0eb63
2 changed files with 10 additions and 21 deletions

View File

@@ -2,14 +2,8 @@ const i18n = require('./.i18nrc');
/** @type {import('next-i18next').UserConfig} */
module.exports = {
debug: false,
fallbackLng: {
default: ['zh_CN'],
},
i18n: {
defaultLocale: i18n.entryLocale,
locales: [i18n.entryLocale, ...i18n.outputLocales],
},
localePath:
typeof window === 'undefined' ? require('node:path').resolve('./public/locales') : '/locales',
};

View File

@@ -1,18 +1,13 @@
import type { GetStaticProps, InferGetStaticPropsType } from 'next';
import { serverSideTranslations } from 'next-i18next/serverSideTranslations';
import { memo } from 'react';
import Chat from './chat/index.page';
export { default } from './chat/index.page';
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const Index = (_props: InferGetStaticPropsType<typeof getStaticProps>) => {
return <Chat />;
};
export const getStaticProps: GetStaticProps = async ({ locale }) => ({
props: {
...(await serverSideTranslations(locale ?? 'zh_CN', ['common'])),
},
});
export default memo(Index);
export async function getStaticProps(context: any) {
const { locale } = context;
return {
props: {
// pass the translation props to the page component
...(await serverSideTranslations(locale)),
},
};
}