From 0d616792dcd4c2413b7e1ceb6eb02d018d075921 Mon Sep 17 00:00:00 2001 From: hdsuperman Date: Thu, 22 Dec 2022 22:21:38 +0800 Subject: [PATCH] chore: code style --- src/i18n.ts | 110 +++++++++++++++++++------------------- src/routes/chat/index.tsx | 2 - src/routes/chat/utils.tsx | 2 +- 3 files changed, 55 insertions(+), 59 deletions(-) diff --git a/src/i18n.ts b/src/i18n.ts index 98e6f0da..f7b94b1d 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -1,68 +1,66 @@ -import i18n from 'i18next'; -import dayjs from 'dayjs'; -import { initReactI18next } from 'react-i18next'; -import Backend from 'i18next-http-backend'; -import LanguageDetector from 'i18next-browser-languagedetector'; -import common from '../public/locales/en/common.json'; +import i18n from "i18next"; +import dayjs from "dayjs"; +import { initReactI18next } from "react-i18next"; +import Backend from "i18next-http-backend"; +import LanguageDetector from "i18next-browser-languagedetector"; +import common from "../public/locales/en/common.json"; -import auth from '../public/locales/en/auth.json'; -import member from '../public/locales/en/member.json'; -import chat from '../public/locales/en/chat.json'; -import fav from '../public/locales/en/fav.json'; -import welcome from '../public/locales/en/welcome.json'; -import setting from '../public/locales/en/setting.json'; -import file from '../public/locales/en/file.json'; +import auth from "../public/locales/en/auth.json"; +import member from "../public/locales/en/member.json"; +import chat from "../public/locales/en/chat.json"; +import fav from "../public/locales/en/fav.json"; +import welcome from "../public/locales/en/welcome.json"; +import setting from "../public/locales/en/setting.json"; +import file from "../public/locales/en/file.json"; // don't want to use this? -// have a look at the Quick start guide +// have a look at the Quick start guide // for passing in lng and translations on init export const defaultNS = "common"; export const resources = { - en: { - common, - chat, - auth, - fav, - member, - welcome, - setting, - file, - }, + en: { + common, + chat, + auth, + fav, + member, + welcome, + setting, + file + } } as const; i18n.on("languageChanged", (lng) => { - console.log("changed", lng); - // 匹配dayjs的多语言关键字 - dayjs.locale(lng === 'zh' ? "zh-cn" : lng === 'jp' ? "ja" : lng); + // 匹配dayjs的多语言关键字 + dayjs.locale(lng === "zh" ? "zh-cn" : lng === "jp" ? "ja" : lng); }); i18n - // load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales) - // learn more: https://github.com/i18next/i18next-http-backend - // want your translations to be loaded from a professional CDN? => https://github.com/locize/react-tutorial#step-2---use-the-locize-cdn - .use(Backend) - // detect user language - // learn more: https://github.com/i18next/i18next-browser-languageDetector - .use(LanguageDetector) - // pass the i18n instance to react-i18next. - .use(initReactI18next) - // init i18next - // for all options read: https://www.i18next.com/overview/configuration-options - .init({ - ns: ["common", "chat", "member", "setting", "fav", "file", "welcome", "auth"], - defaultNS, - load: "languageOnly", - // lng: "jp", - fallbackLng: 'en', - fallbackNS: "common", - debug: false, - detection: { - order: ["localStorage", "navigator"] - }, - interpolation: { - escapeValue: false, // not needed for react as it escapes by default - }, - returnNull: false, - }); + // load translation using http -> see /public/locales (i.e. https://github.com/i18next/react-i18next/tree/master/example/react/public/locales) + // learn more: https://github.com/i18next/i18next-http-backend + // want your translations to be loaded from a professional CDN? => https://github.com/locize/react-tutorial#step-2---use-the-locize-cdn + .use(Backend) + // detect user language + // learn more: https://github.com/i18next/i18next-browser-languageDetector + .use(LanguageDetector) + // pass the i18n instance to react-i18next. + .use(initReactI18next) + // init i18next + // for all options read: https://www.i18next.com/overview/configuration-options + .init({ + ns: ["common", "chat", "member", "setting", "fav", "file", "welcome", "auth"], + defaultNS, + load: "languageOnly", + // lng: "jp", + fallbackLng: "en", + fallbackNS: "common", + debug: false, + detection: { + order: ["localStorage", "navigator"] + }, + interpolation: { + escapeValue: false // not needed for react as it escapes by default + }, + returnNull: false + }); - -export default i18n; \ No newline at end of file +export default i18n; diff --git a/src/routes/chat/index.tsx b/src/routes/chat/index.tsx index ab726a58..6e3851ff 100644 --- a/src/routes/chat/index.tsx +++ b/src/routes/chat/index.tsx @@ -1,7 +1,5 @@ -// import React from 'react'; import { memo, useState } from "react"; import { useParams } from "react-router-dom"; - import StyledWrapper from "./styled"; import BlankPlaceholder from "../../common/component/BlankPlaceholder"; import Server from "../../common/component/Server"; diff --git a/src/routes/chat/utils.tsx b/src/routes/chat/utils.tsx index 7641ee21..9a13bff0 100644 --- a/src/routes/chat/utils.tsx +++ b/src/routes/chat/utils.tsx @@ -1,4 +1,4 @@ -import React, { ReactElement, ReactNode } from "react"; +import React from "react"; import dayjs from "dayjs"; import styled from "styled-components"; import reactStringReplace from "react-string-replace";