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-11-09 19:04:16 +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
|
|
|
if (locale === 'hi') {
|
2023-11-20 22:29:27 +01:00
|
|
|
i18n.loadAndActivate({locale, messages: messagesHi})
|
|
|
|
} else {
|
|
|
|
i18n.loadAndActivate({locale, messages: messagesEn})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function useLocaleLanguage() {
|
|
|
|
const {appLanguage} = useLanguagePrefs()
|
|
|
|
useEffect(() => {
|
|
|
|
dynamicActivate(appLanguage)
|
|
|
|
}, [appLanguage])
|
2023-11-09 19:04:16 +01:00
|
|
|
}
|