i18n settings improvements (#2184)
* Handle language selector * Improve type safety * Add a little more safety * Update comment
This commit is contained in:
+11
-12
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user