import {useEffect} from 'react' import {i18n} from '@lingui/core' import {useLanguagePrefs} from '#/state/preferences' 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) { let mod: any switch (locale) { case AppLanguage.hi: { mod = await import(`./locales/hi/messages`) break } default: { mod = await import(`./locales/en/messages`) break } } i18n.load(locale, mod.messages) i18n.activate(locale) } export async function useLocaleLanguage() { const {appLanguage} = useLanguagePrefs() useEffect(() => { dynamicActivate(sanitizeAppLanguageSetting(appLanguage)) }, [appLanguage]) }