Improve i18n resource loading mechanism

This commit is contained in:
giancarlo
2024-04-20 02:12:36 +08:00
parent c3d2e29f1b
commit ecdb9ac717

View File

@@ -18,22 +18,11 @@ export async function initializeI18nClient(
return Promise.resolve(clientInstance);
}
const loadedLanguages: string[] = [];
const loadedNamespaces: string[] = [];
await i18next
.use(
resourcesToBackend(async (language, namespace, callback) => {
const data = await resolver(language, namespace);
if (!loadedLanguages.includes(language)) {
loadedLanguages.push(language);
}
if (!loadedNamespaces.includes(namespace)) {
loadedNamespaces.push(namespace);
}
return callback(null, data);
}),
)
@@ -58,19 +47,6 @@ export async function initializeI18nClient(
},
);
// keep component suspended until all languages and namespaces are loaded
if (loadedNamespaces.length !== settings.ns?.length) {
throw new Error();
}
if (
loadedLanguages.length !==
((settings.supportedLngs as string[]) ?? [])?.length
) {
throw new Error();
}
clientInstance = i18next;
return clientInstance;