From d8959bc897ccadb3083f59f31fc041b42f1b9466 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 10 Jul 2023 18:28:54 +0800 Subject: Now front end is ok! --- FrontEnd/src/@types/parcel-env.d.ts | 1 + FrontEnd/src/@types/vite-env.d.ts | 1 - FrontEnd/src/i18n.ts | 56 ++++++++++++++----------------------- FrontEnd/src/index.css | 6 ++-- FrontEnd/src/index.tsx | 1 - 5 files changed, 25 insertions(+), 40 deletions(-) create mode 100644 FrontEnd/src/@types/parcel-env.d.ts delete mode 100644 FrontEnd/src/@types/vite-env.d.ts (limited to 'FrontEnd/src') diff --git a/FrontEnd/src/@types/parcel-env.d.ts b/FrontEnd/src/@types/parcel-env.d.ts new file mode 100644 index 00000000..f9bc1f6b --- /dev/null +++ b/FrontEnd/src/@types/parcel-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/FrontEnd/src/@types/vite-env.d.ts b/FrontEnd/src/@types/vite-env.d.ts deleted file mode 100644 index 11f02fe2..00000000 --- a/FrontEnd/src/@types/vite-env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// diff --git a/FrontEnd/src/i18n.ts b/FrontEnd/src/i18n.ts index 6a38e5b4..ad261c6e 100644 --- a/FrontEnd/src/i18n.ts +++ b/FrontEnd/src/i18n.ts @@ -4,39 +4,25 @@ import { initReactI18next } from "react-i18next"; const backend: BackendModule = { type: "backend", - read(language, namespace, callback) { - function error(message: string): void { - callback(new Error(message), false); - } - - function success(result: ResourceKey): void { - callback(null, result); - } - - const promise = (() => { - if (namespace === "translation") { - if (language === "en") { - return import("./locales/en/translation.json"); - } else if (language === "zh") { - return import("./locales/zh/translation.json"); - } else { - error(`Language ${language} is not supported.`); - } - } else if (namespace === "admin") { - if (language === "en") { - return import("./locales/en/admin.json"); - } else if (language === "zh") { - return import("./locales/zh/admin.json"); - } else { - error(`Language ${language} is not supported.`); - } + async read(language, namespace) { + if (namespace === "translation") { + if (language === "en") { + return await import("./locales/en/translation.json"); + } else if (language === "zh") { + return await import("./locales/zh/translation.json"); } else { - error(`Namespace ${namespace} is not supported.`); + throw Error(`Language ${language} is not supported.`); } - })(); - - if (promise) { - void promise.then((d) => success(d.default)); + } else if (namespace === "admin") { + if (language === "en") { + return await import("./locales/en/admin.json"); + } else if (language === "zh") { + return await import("./locales/zh/admin.json"); + } else { + throw Error(`Language ${language} is not supported.`); + } + } else { + throw Error(`Namespace ${namespace} is not supported.`); } }, init() {}, // eslint-disable-line @typescript-eslint/no-empty-function @@ -51,7 +37,7 @@ export const i18nPromise = i18n fallbackLng: false, lowerCaseLng: true, - debug: import.meta.env.DEV, + debug: process.env.NODE_ENV === "development", interpolation: { escapeValue: false, // not needed for react!! @@ -71,8 +57,8 @@ export const i18nPromise = i18n */ }); -if (import.meta.hot) { - import.meta.hot.accept( +if (module.hot) { + module.hot.accept( [ "./locales/en/translation.json", "./locales/zh/translation.json", @@ -81,7 +67,7 @@ if (import.meta.hot) { ], () => { void i18n.reloadResources(); - } + }, ); } diff --git a/FrontEnd/src/index.css b/FrontEnd/src/index.css index 97759b8a..419ccb8c 100644 --- a/FrontEnd/src/index.css +++ b/FrontEnd/src/index.css @@ -1,6 +1,6 @@ -@import "bootstrap/dist/css/bootstrap-reboot.css"; -@import "bootstrap/dist/css/bootstrap-grid.css"; -@import "bootstrap-icons/font/bootstrap-icons.css"; +@import "npm:bootstrap/dist/css/bootstrap-reboot.css"; +@import "npm:bootstrap/dist/css/bootstrap-grid.css"; +@import "npm:bootstrap-icons/font/bootstrap-icons.css"; @import "./views/common/index.css"; diff --git a/FrontEnd/src/index.tsx b/FrontEnd/src/index.tsx index a087fb8a..ba61d357 100644 --- a/FrontEnd/src/index.tsx +++ b/FrontEnd/src/index.tsx @@ -9,7 +9,6 @@ import "./index.css"; import "./i18n"; import "./palette"; -import "./service-worker"; import App from "./App"; -- cgit v1.2.3