Refactor i18n settings and improve language load handling
This update separates the creation of i18n settings into its own function (@kit/i18n) and enhances the handling of language and namespace loading in i18n.client. It tracks loaded languages and namespaces, and prevents rendering if none are loaded or after a maximum number of iterations. The usage of Suspense has also been modified in root-providers to employ a null fallback.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { InitOptions } from 'i18next';
|
||||
import { createI18nSettings } from '@kit/i18n';
|
||||
|
||||
/**
|
||||
* The default language of the application.
|
||||
@@ -43,7 +43,7 @@ export const defaultI18nNamespaces = [
|
||||
export function getI18nSettings(
|
||||
language: string | undefined,
|
||||
ns: string | string[] = defaultI18nNamespaces,
|
||||
): InitOptions {
|
||||
) {
|
||||
let lng = language ?? defaultLanguage;
|
||||
|
||||
if (!languages.includes(lng)) {
|
||||
@@ -54,18 +54,9 @@ export function getI18nSettings(
|
||||
lng = defaultLanguage;
|
||||
}
|
||||
|
||||
return {
|
||||
supportedLngs: languages,
|
||||
fallbackLng: languages[0],
|
||||
detection: undefined,
|
||||
lng,
|
||||
load: 'languageOnly',
|
||||
preload: false,
|
||||
lowerCaseLng: true,
|
||||
fallbackNS: defaultI18nNamespaces,
|
||||
ns,
|
||||
react: {
|
||||
useSuspense: true,
|
||||
},
|
||||
};
|
||||
return createI18nSettings({
|
||||
language: lng,
|
||||
namespaces: ns,
|
||||
languages,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user