From 6308cbc2e4e614e581d6ad65962eca85848d91e7 Mon Sep 17 00:00:00 2001 From: yyy <1174643184@qq.com> Date: Sat, 18 May 2024 21:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=9A=E8=BF=87=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=88=87=E6=8D=A2=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/layout/index.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/router/layout/index.tsx b/src/router/layout/index.tsx index af80c6d..8eb2ad2 100644 --- a/src/router/layout/index.tsx +++ b/src/router/layout/index.tsx @@ -6,10 +6,12 @@ import { observer } from 'mobx-react'; import { useEffect } from 'react'; import store from '~/store'; import { initContract } from '~/contract'; +import { useTranslation } from 'react-i18next'; const LayoutRouter = () => { - const { location } = useRouter() + const { location, push } = useRouter() + const { i18n } = useTranslation() const { walletAddress } = store.state useEffect(() => { @@ -33,9 +35,21 @@ const LayoutRouter = () => { } }); + initLanguage() + }, []) + const initLanguage = () => { + let pathname = location.pathname.slice(1) + + if (pathname === 'zh' || pathname === 'hk' || pathname === 'en') { + i18n.changeLanguage(pathname) + push('/', null, true) + } + + } + return (