diff --git a/desktop/src/lib/i18n.ts b/desktop/src/lib/i18n.ts index a3f22890..1833728d 100644 --- a/desktop/src/lib/i18n.ts +++ b/desktop/src/lib/i18n.ts @@ -14,7 +14,7 @@ export const supportedLanguages: { [key: string]: string } = { 'fr-FR': 'french', 'pl-PL': 'polish', 'it-IT': 'italian', - 'hi-IN': 'hindi' + 'hi-IN': 'hindi', } export const supportedLanguageKeys = Object.keys(supportedLanguages) export const supportedLanguageValues = Object.values(supportedLanguages) @@ -29,8 +29,14 @@ const LanguageDetector: LanguageDetectorAsyncModule = { async: true, // If this is set to true, your detect function receives a callback function that you should call with your language, useful to retrieve your language stored in AsyncStorage for example detect: (callback) => { locale().then((detectedLocale) => { - if (detectedLocale) { - callback(detectedLocale) + const prefs_language = localStorage.getItem('prefs_display_language') + if (prefs_language) { + const locale = JSON.parse(prefs_language) + callback(locale) + } else { + if (detectedLocale) { + callback(detectedLocale) + } } }) }, diff --git a/desktop/src/providers/Preference.tsx b/desktop/src/providers/Preference.tsx index b1ff2e98..7455d277 100644 --- a/desktop/src/providers/Preference.tsx +++ b/desktop/src/providers/Preference.tsx @@ -111,6 +111,10 @@ export function PreferenceProvider({ children }: { children: ReactNode }) { } } useEffect(() => { + if (!isMounted.current) { + isMounted.current = true + return + } changeLanguage() }, [language])