diff options
author | crupest <crupest@outlook.com> | 2023-07-11 01:07:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-11 01:07:57 +0800 |
commit | a702dff4b62090a4e5453a8b9236824288df0c4f (patch) | |
tree | 0deae7f40692345c8e4b1473cdddbd13e0e5586d /FrontEnd/src/i18n.ts | |
parent | 4cb87464fea217e1d0969747d6a17e88973982e7 (diff) | |
parent | d46b1aed549938c9f5e3e658b4098e71b5e2acf7 (diff) | |
download | timeline-a702dff4b62090a4e5453a8b9236824288df0c4f.tar.gz timeline-a702dff4b62090a4e5453a8b9236824288df0c4f.tar.bz2 timeline-a702dff4b62090a4e5453a8b9236824288df0c4f.zip |
Merge pull request #1381 from crupest/front-dev
Re-bootstrap front end.
Diffstat (limited to 'FrontEnd/src/i18n.ts')
-rw-r--r-- | FrontEnd/src/i18n.ts | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/FrontEnd/src/i18n.ts b/FrontEnd/src/i18n.ts index 6a38e5b4..9bf8721f 100644 --- a/FrontEnd/src/i18n.ts +++ b/FrontEnd/src/i18n.ts @@ -1,43 +1,34 @@ -import i18n, { BackendModule, ResourceKey } from "i18next"; +import i18n, { BackendModule } from "i18next"; import LanguageDetector from "i18next-browser-languagedetector"; 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 = (() => { + (async () => { if (namespace === "translation") { if (language === "en") { - return import("./locales/en/translation.json"); + return await import("./locales/en/translation.json"); } else if (language === "zh") { - return import("./locales/zh/translation.json"); + return await import("./locales/zh/translation.json"); } else { - error(`Language ${language} is not supported.`); + throw Error(`Language ${language} is not supported.`); } } else if (namespace === "admin") { if (language === "en") { - return import("./locales/en/admin.json"); + return await import("./locales/en/admin.json"); } else if (language === "zh") { - return import("./locales/zh/admin.json"); + return await import("./locales/zh/admin.json"); } else { - error(`Language ${language} is not supported.`); + throw Error(`Language ${language} is not supported.`); } } else { - error(`Namespace ${namespace} is not supported.`); + throw Error(`Namespace ${namespace} is not supported.`); } - })(); - - if (promise) { - void promise.then((d) => success(d.default)); - } + })().then( + (resources) => callback(null, resources.default), + (error: Error) => callback(error, null), + ); }, init() {}, // eslint-disable-line @typescript-eslint/no-empty-function create() {}, // eslint-disable-line @typescript-eslint/no-empty-function @@ -51,7 +42,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 +62,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 +72,7 @@ if (import.meta.hot) { ], () => { void i18n.reloadResources(); - } + }, ); } |