You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
933 B

import App, { AppContext, AppProps } from "next/app";
import { NextIntlProvider } from "next-intl";
import { useRouter } from "next/router";
import cookies from "next-cookies";
const twMessages = require(`../public/h5_assets/messages/zh_TW/common.json`);
const cnMessages = require(`../public/h5_assets/messages/zh_CN/common.json`);
const MyApp = ({ Component, pageProps }: AppProps) => {
let router = useRouter();
return (
<NextIntlProvider
messages={(pageProps.lang ?? router.locale) === "zh_CN" ? { ...cnMessages } : { ...twMessages }}
>
<Component {...pageProps} />
</NextIntlProvider>
);
};
MyApp.getInitialProps = async (props: AppContext) => {
const NEXT_LOCALE = cookies(props.ctx)["NEXT_LOCALE"];
const appProps = await App.getInitialProps(props);
appProps.pageProps = {
...appProps.pageProps,
lang: NEXT_LOCALE,
};
return { ...appProps };
};
export default MyApp;