Skip to content

Commit

Permalink
Merge pull request #1384 from crupest/fix-i18next
Browse files Browse the repository at this point in the history
Fix #1383.
  • Loading branch information
crupest committed Jul 11, 2023
2 parents 1d5fbed + 3c9f705 commit c80bbe2
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions FrontEnd/src/i18n.ts
Expand Up @@ -4,34 +4,31 @@ import { initReactI18next } from "react-i18next";

const backend: BackendModule = {
type: "backend",
read(language, namespace, callback) {
(async () => {
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 {
throw Error(`Language ${language} is not supported.`);
}
} 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.`);
}
init() {
/* do nothing */
},
// eslint-disable-next-line @typescript-eslint/no-misused-promises
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 {
throw Error(`Language ${language} is not supported.`);
}
} 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(`Namespace ${namespace} is not supported.`);
throw Error(`Language ${language} is not supported.`);
}
})().then(
(resources) => callback(null, resources.default),
(error: Error) => callback(error, null),
);
} else {
throw Error(`Namespace ${namespace} is not supported.`);
}
},
init() {}, // eslint-disable-line @typescript-eslint/no-empty-function
create() {}, // eslint-disable-line @typescript-eslint/no-empty-function
};

export const i18nPromise = i18n
Expand Down

0 comments on commit c80bbe2

Please sign in to comment.