Improve i18n resource loading mechanism
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user