Skip to content

Commit

Permalink
fix language detection on init
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle committed Aug 7, 2024
1 parent 082d4cf commit 8a980a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions desktop/src/lib/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
})
},
Expand Down
4 changes: 4 additions & 0 deletions desktop/src/providers/Preference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export function PreferenceProvider({ children }: { children: ReactNode }) {
}
}
useEffect(() => {
if (!isMounted.current) {
isMounted.current = true
return
}
changeLanguage()
}, [language])

Expand Down

0 comments on commit 8a980a7

Please sign in to comment.