refactor(i18n): optimize translation loading and initialization

- Updated ensureTranslationsLoaded function to prevent duplicate requests by caching loaded translations and managing loading promises.
- Simplified translation preloading on app startup to only load essential namespaces for the current language.
- Adjusted useTranslationPreloader hook to avoid multiple requests for translations and ensure efficient loading state management.
This commit is contained in:
chamikaJ
2025-07-07 12:31:11 +05:30
parent a6f9046b42
commit 26b47aac53
3 changed files with 81 additions and 32 deletions

View File

@@ -2,7 +2,6 @@
import React, { Suspense, useEffect, memo, useMemo, useCallback } from 'react';
import { RouterProvider } from 'react-router-dom';
import i18next from 'i18next';
import { ensureTranslationsLoaded } from './i18n';
// Components
import ThemeWrapper from './features/theme/ThemeWrapper';
@@ -66,8 +65,8 @@ const App: React.FC = memo(() => {
// Initialize CSRF token
await initializeCsrfToken();
// Preload essential translations
await ensureTranslationsLoaded();
// Note: Translation preloading is handled in i18n.ts initialization
// No need to call ensureTranslationsLoaded here to avoid duplicate requests
} catch (error) {
if (isMounted) {
logger.error('Failed to initialize app:', error);