i18n settings improvements (#2184)
* Handle language selector * Improve type safety * Add a little more safety * Update comment
This commit is contained in:
parent
d82b1a1047
commit
c6ab6e8b8e
7 changed files with 79 additions and 39 deletions
|
@ -3,24 +3,23 @@ import {i18n} from '@lingui/core'
|
|||
|
||||
import {useLanguagePrefs} from '#/state/preferences'
|
||||
import {sanitizeAppLanguageSetting} from '#/locale/helpers'
|
||||
|
||||
export const locales = {
|
||||
en: 'English',
|
||||
hi: 'हिंदी',
|
||||
}
|
||||
export const defaultLocale = 'en'
|
||||
import {AppLanguage} from '#/locale/languages'
|
||||
|
||||
/**
|
||||
* We do a dynamic import of just the catalog that we need
|
||||
* @param locale any locale string
|
||||
*/
|
||||
export async function dynamicActivate(locale: string) {
|
||||
export async function dynamicActivate(locale: AppLanguage) {
|
||||
let mod: any
|
||||
|
||||
if (locale === 'hi') {
|
||||
mod = await import(`./locales/hi/messages`)
|
||||
} else {
|
||||
mod = await import(`./locales/en/messages`)
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue