2023-11-24 21:35:25 +01:00
|
|
|
import {useEffect} from 'react'
|
2023-12-06 02:51:50 +01:00
|
|
|
import {i18n} from '@lingui/core'
|
|
|
|
|
|
|
|
import {useLanguagePrefs} from '#/state/preferences'
|
2023-11-24 21:35:25 +01:00
|
|
|
|
|
|
|
export const locales = {
|
|
|
|
en: 'English',
|
|
|
|
hi: 'हिंदी',
|
|
|
|
}
|
|
|
|
export const defaultLocale = 'en'
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We do a dynamic import of just the catalog that we need
|
|
|
|
* @param locale any locale string
|
|
|
|
*/
|
|
|
|
export async function dynamicActivate(locale: string) {
|
2023-12-06 02:51:50 +01:00
|
|
|
let mod: any
|
|
|
|
|
|
|
|
if (locale === 'hi') {
|
|
|
|
mod = await import(`./locales/hi/messages`)
|
|
|
|
} else {
|
|
|
|
mod = await import(`./locales/en/messages`)
|
|
|
|
}
|
|
|
|
|
|
|
|
i18n.load(locale, mod.messages)
|
2023-11-24 21:35:25 +01:00
|
|
|
i18n.activate(locale)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function useLocaleLanguage() {
|
|
|
|
const {appLanguage} = useLanguagePrefs()
|
|
|
|
useEffect(() => {
|
|
|
|
dynamicActivate(appLanguage)
|
|
|
|
}, [appLanguage])
|
|
|
|
}
|