This commit is contained in:
2021-07-07 16:26:37 +08:00
parent d7f9f7068e
commit e6fd3f33e5
16 changed files with 926 additions and 227 deletions
+33 -6
View File
@@ -1,7 +1,34 @@
import '../styles/globals.css'
import type { AppProps } from 'next/app'
import App, { AppContext, AppProps } from "next/app";
import { NextIntlProvider } from "next-intl";
import { useRouter } from "next/router";
import cookies from "next-cookies";
function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
}
export default MyApp
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;
-13
View File
@@ -1,13 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data>
) {
res.status(200).json({ name: 'John Doe' })
}
+15 -66
View File
@@ -1,69 +1,18 @@
import Head from 'next/head'
import Image from 'next/image'
import styles from '../styles/Home.module.css'
import React from "react";
import { useTranslations } from "next-intl";
import { KEYS } from "../lib/keys";
const IndexPage: React.FC = () => {
let t = useTranslations();
export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>Create Next App</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>
<p className={styles.description}>
Get started by editing{' '}
<code className={styles.code}>pages/index.js</code>
</p>
<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Documentation &rarr;</h2>
<p>Find in-depth information about Next.js features and API.</p>
</a>
<a href="https://nextjs.org/learn" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js in an interactive course with quizzes!</p>
</a>
<a
href="https://github.com/vercel/next.js/tree/master/examples"
className={styles.card}
>
<h2>Examples &rarr;</h2>
<p>Discover and deploy boilerplate example Next.js projects.</p>
</a>
<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
className={styles.card}
>
<h2>Deploy &rarr;</h2>
<p>
Instantly deploy your Next.js site to a public URL with Vercel.
</p>
</a>
</div>
</main>
<footer className={styles.footer}>
<a
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
Powered by{' '}
<span className={styles.logo}>
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
</span>
</a>
</footer>
<div>
{
t(KEYS.UI$bloodGlucose$about)
}
</div>
)
}
);
};
export default IndexPage;
+18
View File
@@ -0,0 +1,18 @@
import React from "react";
import { useTranslations } from "next-intl";
import { KEYS } from "../../lib/keys";
const IndexPage: React.FC = () => {
let t = useTranslations();
return (
<div>
{
t(KEYS.UI$tabs$quota, { p: 9 })
}
</div>
);
};
export default IndexPage;