From 646a41e9313117fa5ef7dbd826cdef49628c1380 Mon Sep 17 00:00:00 2001 From: boojack Date: Sun, 7 Aug 2022 22:48:22 +0800 Subject: [PATCH] chore: add `i18n` based with `useContext` --- web/src/components/AboutSiteDialog.tsx | 9 +++- web/src/hooks/useDebounce.ts | 27 ------------ web/src/hooks/useI18n.ts | 3 ++ web/src/hooks/useLoading.ts | 6 ++- web/src/hooks/useRefresh.ts | 6 ++- web/src/hooks/useToggle.ts | 6 ++- web/src/labs/i18n/I18nProvider.tsx | 27 ++++++++++++ web/src/labs/i18n/i18nStore.ts | 58 ++++++++++++++++++++++++++ web/src/labs/i18n/useI18n.ts | 47 +++++++++++++++++++++ web/src/locales/en.json | 3 ++ web/src/locales/zh.json | 3 ++ web/src/main.tsx | 9 ++-- web/src/services/resourceService.ts | 5 --- web/src/store/index.ts | 4 +- 14 files changed, 168 insertions(+), 45 deletions(-) delete mode 100644 web/src/hooks/useDebounce.ts create mode 100644 web/src/hooks/useI18n.ts create mode 100644 web/src/labs/i18n/I18nProvider.tsx create mode 100644 web/src/labs/i18n/i18nStore.ts create mode 100644 web/src/labs/i18n/useI18n.ts create mode 100644 web/src/locales/en.json create mode 100644 web/src/locales/zh.json diff --git a/web/src/components/AboutSiteDialog.tsx b/web/src/components/AboutSiteDialog.tsx index d7a0b9ef3..fa4ed6ed9 100644 --- a/web/src/components/AboutSiteDialog.tsx +++ b/web/src/components/AboutSiteDialog.tsx @@ -1,5 +1,6 @@ import { useEffect, useState } from "react"; import * as api from "../helpers/api"; +import useI18n from "../hooks/useI18n"; import Only from "./common/OnlyWhen"; import Icon from "./Icon"; import { generateDialog } from "./Dialog"; @@ -10,6 +11,7 @@ interface Props extends DialogProps {} const AboutSiteDialog: React.FC = ({ destroy }: Props) => { const [profile, setProfile] = useState(); + const { t, setLocale } = useI18n(); useEffect(() => { try { @@ -25,6 +27,10 @@ const AboutSiteDialog: React.FC = ({ destroy }: Props) => { version: "0.0.0", }); } + + setTimeout(() => { + setLocale("zh"); + }, 2333); }, []); const handleCloseBtnClick = () => { @@ -35,7 +41,8 @@ const AboutSiteDialog: React.FC = ({ destroy }: Props) => { <>

- 🤠About Memos + 🤠 + {t("about")} Memos