Refactor i18n client and server initialization
The refactor includes the removal of clientInstance checks as they are unnecessary. Also, i18n-provider.tsx has been updated to use react-query instead of local state for client initialization. Lastly, error handling has been added to the server initialization process and the @tanstack/react-query package has been added to the project dependencies.
This commit is contained in:
@@ -14,10 +14,6 @@ export async function initializeServerI18n(
|
||||
) {
|
||||
const i18nInstance = createInstance();
|
||||
|
||||
if (i18nInstance.isInitialized) {
|
||||
return i18nInstance;
|
||||
}
|
||||
|
||||
await i18nInstance
|
||||
.use(
|
||||
resourcesToBackend(async (language, namespace, callback) => {
|
||||
@@ -36,11 +32,20 @@ export async function initializeServerI18n(
|
||||
}),
|
||||
)
|
||||
.use(initReactI18next)
|
||||
.init(settings);
|
||||
.init(settings, (error) => {
|
||||
if (error) {
|
||||
console.error('Error initializing i18n server', error);
|
||||
}
|
||||
});
|
||||
|
||||
return i18nInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the accept-language header value and return the languages that are included in the accepted languages.
|
||||
* @param languageHeaderValue
|
||||
* @param acceptedLanguages
|
||||
*/
|
||||
export function parseAcceptLanguageHeader(
|
||||
languageHeaderValue: string | null | undefined,
|
||||
acceptedLanguages: string[],
|
||||
|
||||
Reference in New Issue
Block a user