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:
@@ -26,7 +26,7 @@ export const useTranslationPreloader = (
|
||||
try {
|
||||
setIsLoading(true);
|
||||
|
||||
// Ensure translations are loaded
|
||||
// Only load translations for current language to avoid multiple requests
|
||||
await ensureTranslationsLoaded(namespaces);
|
||||
|
||||
// Wait for i18next to be ready
|
||||
@@ -47,12 +47,18 @@ export const useTranslationPreloader = (
|
||||
}
|
||||
};
|
||||
|
||||
loadTranslations();
|
||||
// Only load if not already loaded
|
||||
if (!isLoaded && !ready) {
|
||||
loadTranslations();
|
||||
} else if (ready && !isLoaded) {
|
||||
setIsLoaded(true);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
};
|
||||
}, [namespaces, ready]);
|
||||
}, [namespaces, ready, isLoaded]);
|
||||
|
||||
return {
|
||||
t,
|
||||
|
||||
Reference in New Issue
Block a user