i18n settings improvements (#2184)

* Handle language selector

* Improve type safety

* Add a little more safety

* Update comment
This commit is contained in:
Eric Bailey 2023-12-12 12:42:11 -06:00 committed by GitHub
parent d82b1a1047
commit c6ab6e8b8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 79 additions and 39 deletions

View file

@ -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)