feat: init i18n with custom language detector

This commit is contained in:
DIYgod
2023-02-22 04:05:16 +00:00
parent 14dedbe891
commit 20b64ff247
9 changed files with 114 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
import type { GetServerSidePropsContext } from "next"
export const languageDetector = (ctx: GetServerSidePropsContext) => {
return ctx.req.headers["accept-language"]?.split(",")[0].split("-")[0] || "en"
}
+2 -1
View File
@@ -11,6 +11,7 @@ import { NotificationModal } from "@crossbell/notification"
import { InitContractProvider } from "@crossbell/contract"
import NextNProgress from "nextjs-progressbar"
import { Network } from "crossbell.js"
import { appWithTranslation } from "next-i18next"
import { IPFS_GATEWAY } from "~/lib/env"
import { toGateway } from "~/lib/ipfs-parser"
@@ -78,4 +79,4 @@ function MyApp({ Component, pageProps }: any) {
// return { ...appProps }
// }
export default MyApp
export default appWithTranslation(MyApp)
+6 -1
View File
@@ -33,6 +33,9 @@ import {
XShopLogo,
CrossbellChainLogo,
} from "@crossbell/ui"
import { useTranslation } from "next-i18next"
import { serverSideTranslations } from "next-i18next/serverSideTranslations"
import { languageDetector } from "~/lib/language-detector"
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const queryClient = new QueryClient()
@@ -40,6 +43,7 @@ export const getServerSideProps: GetServerSideProps = async (ctx) => {
return {
props: {
...(await serverSideTranslations(languageDetector(ctx), ["common"])),
dehydratedState: dehydrate(queryClient),
},
}
@@ -49,6 +53,7 @@ export default function Home() {
const isConnected = useAccountState((s) => !!s.computed.account)
const router = useRouter()
const showcaseSites = useGetSites(showcase)
const { t } = useTranslation("common")
const tryNow = useConnectedAction(() => {
router.push("/dashboard")
@@ -60,7 +65,7 @@ export default function Home() {
src: "/assets/easy.png",
},
icon: <LaughIcon />,
title: "Easy",
title: t("easy"),
text: (
<>
Connect with your <span className="font-bold">Web3 Wallet</span> or{" "}