2023-11-20 22:29:27 +01:00
|
|
|
import {useEffect} from 'react'
|
2023-12-06 02:51:50 +01:00
|
|
|
import {i18n} from '@lingui/core'
|
|
|
|
|
|
|
|
import {useLanguagePrefs} from '#/state/preferences'
|
|
|
|
import {messages as messagesEn} from '#/locale/locales/en/messages'
|
|
|
|
import {messages as messagesHi} from '#/locale/locales/hi/messages'
|
2023-12-12 20:42:19 +01:00
|
|
|
import {messages as messagesJa} from '#/locale/locales/ja/messages'
|
2023-12-21 23:00:24 +01:00
|
|
|
import {messages as messagesFr} from '#/locale/locales/fr/messages'
|
2023-12-28 21:07:08 +01:00
|
|
|
// DISABLED until this translation is fixed -prf
|
|
|
|
// import {messages as messagesDe} from '#/locale/locales/de/messages'
|
2023-12-28 22:03:54 +01:00
|
|
|
// DISABLED until this translation is more thoroughly reviewed -prf
|
|
|
|
// import {messages as messagesEs} from '#/locale/locales/es/messages'
|
2023-12-22 19:00:39 +01:00
|
|
|
|
2023-12-12 00:34:18 +01:00
|
|
|
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
2023-12-12 19:42:11 +01:00
|
|
|
import {AppLanguage} from '#/locale/languages'
|
2023-11-09 19:04:16 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We do a dynamic import of just the catalog that we need
|
|
|
|
*/
|
2023-12-12 19:42:11 +01:00
|
|
|
export async function dynamicActivate(locale: AppLanguage) {
|
|
|
|
switch (locale) {
|
|
|
|
case AppLanguage.hi: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesHi})
|
|
|
|
break
|
|
|
|
}
|
2023-12-12 20:42:19 +01:00
|
|
|
case AppLanguage.ja: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesJa})
|
|
|
|
break
|
|
|
|
}
|
2023-12-21 23:00:24 +01:00
|
|
|
case AppLanguage.fr: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesFr})
|
|
|
|
break
|
|
|
|
}
|
2023-12-28 21:07:08 +01:00
|
|
|
// DISABLED until this translation is fixed -prf
|
|
|
|
// case AppLanguage.de: {
|
|
|
|
// i18n.loadAndActivate({locale, messages: messagesDe})
|
|
|
|
// break
|
|
|
|
// }
|
2023-12-28 22:03:54 +01:00
|
|
|
// DISABLED until this translation is more thoroughly reviewed -prf
|
|
|
|
// case AppLanguage.es: {
|
|
|
|
// i18n.loadAndActivate({locale, messages: messagesEs})
|
|
|
|
// break
|
|
|
|
// }
|
2023-12-12 19:42:11 +01:00
|
|
|
default: {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesEn})
|
|
|
|
break
|
|
|
|
}
|
2023-11-20 22:29:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function useLocaleLanguage() {
|
|
|
|
const {appLanguage} = useLanguagePrefs()
|
|
|
|
useEffect(() => {
|
2023-12-12 00:34:18 +01:00
|
|
|
dynamicActivate(sanitizeAppLanguageSetting(appLanguage))
|
2023-11-20 22:29:27 +01:00
|
|
|
}, [appLanguage])
|
2023-11-09 19:04:16 +01:00
|
|
|
}
|