import {useEffect} from 'react' 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' import {sanitizeAppLanguageSetting} from '#/locale/helpers' import {AppLanguage} from '#/locale/languages' /** * We do a dynamic import of just the catalog that we need */ export async function dynamicActivate(locale: AppLanguage) { switch (locale) { case AppLanguage.hi: { i18n.loadAndActivate({locale, messages: messagesHi}) break } default: { i18n.loadAndActivate({locale, messages: messagesEn}) break } } } export async function useLocaleLanguage() { const {appLanguage} = useLanguagePrefs() useEffect(() => { dynamicActivate(sanitizeAppLanguageSetting(appLanguage)) }, [appLanguage]) }